set “id” and “name” for @HtmlEditorFor?

后端 未结 3 1334
[愿得一人]
[愿得一人] 2020-12-16 17:49

I\'m trying to set id and name for @Html.EditorFor, but this isn\'t working:

@H         


        
相关标签:
3条回答
  • 2020-12-16 17:57

    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" >

    0 讨论(0)
  • 2020-12-16 18:01

    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.

    0 讨论(0)
  • 2020-12-16 18:22
     @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

    0 讨论(0)
提交回复
热议问题