How to override the “name” HtmlAttribute of Razor

前端 未结 2 1100
暗喜
暗喜 2021-02-13 12:37
    @Html.RadioButtonFor(Model => Model.Location, \"Location\")
    @Html.LabelFor(Model=>Model.Location,\"Location\")
    @Html.RadioButtonFor(Model=>Model.Mod         


        
相关标签:
2条回答
  • 2021-02-13 12:40

    Just create a dummy property in your Model class like, public string Dummy{get; set;}

    @Html.RadioButtonFor(Model => Model.Location, "LOC", new { @Name = "Dummy"})
    @Html.RadioButtonFor(Model => Model.Model_Number, "MOD", new { @Name = "Dummy" })
    @Html.RadioButtonFor(Model => Model.MovableUnit, "MU", new { @Name = "Dummy" })
    

    Get the value "LOC", "MOD", "MU" using property name 'Dummy'.

    0 讨论(0)
  • 2021-02-13 12:43

    Use the function without "for", then you can specify the name:

    @Html.RadioButton("newname", "value", new { @id="oldname" })
    
    0 讨论(0)
提交回复
热议问题