Use Html.RadioButtonFor and Html.LabelFor for the same Model but different values

前端 未结 7 1829
陌清茗
陌清茗 2020-12-13 02:11

I have this Razor Template

@Html.RadioButtonFor(i => i.Value, \"1\") @Html.LabelFor(i =>
7条回答
  •  我在风中等你
    2020-12-13 02:53

    Not Perfect but work though,

    @ReplaceName(Html.RadioButtonFor(i => i.Value, "1")) @Html.LabelFor(i => i.Value[0], "true")
    @ReplaceName(Html.RadioButtonFor(i => i.Value, "0")) @Html.LabelFor(i => i.Value[1], "false")
    @functions { int counter = 0; MvcHtmlString ReplaceName(MvcHtmlString html){ return MvcHtmlString.Create(html.ToString().Replace("__Value", "__Value_" + counter++ +"_")); } }

提交回复
热议问题