加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 如何覆盖Razor的“名称”HtmlAttribute

发布时间:2020-12-15 06:53:40 所属栏目:百科 来源:网络整理
导读:@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,
@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”?
问题是我想一次只选择一个单选按钮,但在这种情况下,所有这些都可以同时选择.

解决方法

只要在你的Model类中创建一个虚拟属性,
public string Dummy {get;组;}
@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" })

使用属性名称“Dummy”获取值“LOC”,“MOD”,“MU”.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读