如何重写"名"剃刀HtmlAttribute [英] How to override the "name" HtmlAttribute of Razor

查看:104
本文介绍了如何重写"名"剃刀HtmlAttribute的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    @Html.RadioButtonFor(Model => Model.Location, "Location")
    @Html.LabelFor(Model=>Model.Location,"Location")
    @Html.RadioButtonFor(Model=>Model.Model,"Model")
    @Html.LabelFor(Model=>Model.Model,"Model")
    @Html.RadioButtonFor(Model=>Model.MovableUnit,"MU")
    @Html.LabelFor(Model=>Model.MovableUnit,"MU")




   <input id="Location" name="Location" type="radio" value="Location" />
    <label for="Location">Location</label>
    <input id="Model" name="Model" type="radio" value="Model" />
    <label for="Model">Model</label>
    <input id="MovableUnit" name="MovableUnit" type="radio" value="MU" />
    <label for="MovableUnit">MU</label>

如何拥有一个共同的名字=radiobtn上述所有单选按钮?
        问题是我想在一个时间只选择一个单选按钮,但在这种情况下,所有在同一时间可选择

How to have a common name="radiobtn" for all the above Radio buttons? The problem is I want to select only one radio button at a time, but in this case all are selectable at the same time.

推荐答案

只需在创建模型类的虚拟财产一样,
公共字符串假{搞定;设置;}

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

获取值LOC,mod,MU使用属性名称'假'。

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

这篇关于如何重写&QUOT;名&QUOT;剃刀HtmlAttribute的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆