Set "id" and "name" for @HtmlEditorFor?
I am trying to set id and name for @Html.EditorFor , but this does not work:
@Html.EditorFor(model => model.value, new { @id = "testid1", @name="testname1"}) How to set id and name ?
EditorFor does not allow adding htmlAttributes. For specific types of editors, you will need to use TextBoxFor (or any other type that you use).
@Html.TextBoxFor(m => m.value, new { id = "testid1", name="Testname1" }) You can also create a custom editor template for the specific type for which you are creating an editor.
EditorFor allows you to set the name property and id (verified with .Net 4.6.1) @Html.EditorFor(m => m.value, null, "Testname1") will generate <input class="text-box single-line" id="Testname1" name="Testname1" type="text" >
@Html.EditorFor(model => model.Beds[i].BedName, new { htmlAttributes = new { @class = "form-control", Name = "BedName" + Model.Beds[i].bedId, @id = "BedName" + Model.Beds[i].bedId } }) Use insted of @name and add htmlAttributes to your code so that it works for me