我正在尝试设置id
和name
for @Html.EditorFor
,但这不起作用:
@Html.EditorFor(model => model.value, new { @id = "testid1", @name="testname1"})
Run Code Online (Sandbox Code Playgroud)
如何设置id
和name
?
Bui*_*ted 14
EditorFor
不允许添加htmlAttributes.对于您必须使用的特定类型的编辑器TextBoxFor
(或您正在使用的任何类型).
@Html.TextBoxFor(m => m.value, new { id = "testid1", name="Testname1" })
Run Code Online (Sandbox Code Playgroud)
veb*_*ebs 10
@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 } })
Run Code Online (Sandbox Code Playgroud)
使用名称为@name的名称,并在代码中添加htmlAttributes对我有用
EditorFor允许设置name和id属性(用.Net 4.6.1测试)@Html.EditorFor(m => m.value, null, "Testname1")
将生成<input class="text-box single-line" id="Testname1" name="Testname1" type="text" >