We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Nested template value is not deserialized into object property

I am using a generic template inside the dialog for editing the grid row item.
it looks like this -
 
@using (Html.BeginForm()){
    @Html.EditorForModel()
}
 
 
My model has a Editor Template that looks like this -
 
<fieldset>
    <legend>Environment</legend>
    <div>@Html.EditorFor(m=>m.Id)</div>
    <div>
        <div>
            @Html.LabelFor(m=>m.Name)
        </div>
        <div>
            @Html.EditorFor(m=>m.Name)
        </div>
    </div>
        <div>
        <div>
            @Html.LabelFor(m=>m.AccountId)
        </div>
        <div>
            @Html.EditorFor(m=>m.AccountId)
        </div>
    </div>   
    <div>
        <div>
            @Html.LabelFor(m=>m.ContactId)
        </div>
        <div>
            @Html.EditorFor(m=>m.ContactId)
        </div>
    </div>   
    <div>
        <div>
            @Html.LabelFor(m=>m.ExternalId)
        </div>
        <div>
            @Html.EditorFor(m=>m.ExternalId)
        </div>
    </div>   
</fieldset>

 

And the AccountId inside that template has an EditorTemplate that looks like this -

@Html.DropDownList("Account", new SelectList(MyClass.GetAccounts(), "Id", "Name", Model), new { id = "AccountId", name = "AccountId" })

You can see that I added the html attributes "id" and "name".

The problem I am having, is that form values are not being added to the object when it's deserialized. The "name" attribute looks like AccountId.Account and the "id" attribute looks like AccountId.AccountId.
I added the html attributes to try matching the correct values manually, but the "name" attribute doesn't stick.

Is this a bug?


2 Replies

JB Jeremy Branham October 19, 2013 05:10 PM UTC

I realized this is default MVC behavior. To change this, I would need to build a custom model binder.
I'll just copy/paste view configurations for now.


SK Shanmugaraja K Syncfusion Team October 23, 2013 04:36 AM UTC

Hi  Jeremy,

Thanks for your update.

we will wait to hear from you.

Please let me know if you need further assistance.

Regards,
Shanmugaraja K

Loader.
Live Chat Icon For mobile
Up arrow icon