Asp.net-Mvc-3
為@HtmlEditorFor 設置“id”和“name”?
我正在嘗試設置
id和namefor@Html.EditorFor,但這不起作用:@Html.EditorFor(model => model.value, new { @id = "testid1", @name="testname1"})如何設置
id和name?
EditorFor不允許添加 htmlAttributes。對於您必須使用的特定類型的編輯器TextBoxFor(或您正在使用的任何類型)。@Html.TextBoxFor(m => m.value, new { id = "testid1", name="Testname1" })您還可以為要為其創建編輯器的特定類型創建自定義編輯器模板。
@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 } })使用Name insted of @name 並在您的程式碼中添加 htmlAttributes 它對我有用