I'm trying to set id
and name
for @Html.EditorFor
, but this isn't working:
@Html.EditorFor(model => model.value, new { @id = "testid1", @name="testname1"})
How do I set id
and name
?
I'm trying to set id
and name
for @Html.EditorFor
, but this isn't working:
@Html.EditorFor(model => model.value, new { @id = "testid1", @name="testname1"})
How do I set id
and name
?
EditorFor
does not allow for adding htmlAttributes. For the specific types of editors you'll have to use TextBoxFor
(or whatever type you're using).
@Html.TextBoxFor(m => m.value, new { id = "testid1", name="Testname1" })
You can also create a custom editor template for the particular type you're creating an editor for.
@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 Name insted of @name and add htmlAttributes in your code its working for me
EditorFor allows to set name and id property (tested 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" >