How to override the “name” HtmlAttribute of Razor

前端 未结 2 1103
暗喜
暗喜 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'.

提交回复
热议问题