I looked at several different answers related to this, but they were all for mvc3 or not for Razor.
I have one page with several forms, in partial views, which are designed to edit different models. However, most of these models have a name field. I am looking to be able to specify an editorfor with a specific identifier as such:
<div class="editor-label"> @Html.LabelFor(model => model.Name) </div> <div class="editor-field"> @Html.EditorFor(model => model.Name, new {id = "PersonName"}) @Html.ValidationMessageFor(model => model.Name) </div>
I tried different things, but did not find a satisfactory way to handle this. I seem to have two options:
1) Create a form manually using regular html helpers and build the model in the controller
2) Rename all fields in the model according to the format
None of them excite me, so I hope for an alternative, but I'm afraid that id is what is used when binding the form to the model.
Bear source share