Not working in EditorTemplates

Feb 7, 2014 at 10:19 PM
Edited Feb 7, 2014 at 10:21 PM
I'm using @Html.Html5TextBoxFor in a partial view that is being used as a EditorTemplate. (in /Views/Shared/EditorTemplates, placed in the main view with @Html.EditorFor(), etc.)


What is supposed to happen, when a partial is injected into a page as an editor template is that all of the elements have their ids and names prefixed with the name of the property that the template is loaded for.

E.g.
  • I have a class Address, with a property HouseNumber of type int
  • I have a class Customer, with a property HomeAddress of type Address
  • I have a partial view with @model Address, named /Views/Shared/Address.cshtml
  • I have a view with @model Customer
    • In that view, I insert the address partial using @HtmlEditorFor(m => m.HomeAddress)
In those circumstances, the <input> injected into the page should have an id = "homeaddress_housenumber" and a name of "homeaddress.housenumber", instead of "housenumber" and "housenumber", as would have happened had the partial been included via RenderPartial.

That's exactly what happens, when I use any other html helper. @Html.TextBoxFor(), for example, works as expected. @Html.Html5TextBoxFor does not. It fails to properly prefix the id and name, and because of this the default binder does not correctly populate the model on HttpPost.
Coordinator
Feb 10, 2014 at 10:58 AM
Hi jdege

Thanks for submitting this, I will take a closer look and get back to you shortly.

Thanks
Dean