首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mvc Razor语法中的RadiobuttonFor

Mvc Razor语法中的RadiobuttonFor
EN

Stack Overflow用户
提问于 2014-05-08 06:45:17
回答 1查看 36.6K关注 0票数 13

我有三个单选按钮,我的字段值类型是整型,如维护3、活动1和非活动2。

代码语言:javascript
复制
@Html.RadioButtonFor(model => model.StatusId, "3") Maintenance
@if (Model.IsReady == true)
{
    <span> @Html.RadioButtonFor(model => model.StatusId,"1") Active</span>
}
@Html.RadioButtonFor(model => model.StatusId, "2") Inactive

我使用上面的代码,然后正确地插入数据,但是当我的表单在编辑模式下打开时,我没有选择任何单选按钮。

我也使用了下面的代码,但没有成功。

代码语言:javascript
复制
@Html.RadioButtonFor(model => model.StatusId, "3", Model.StatusId == '3' ? new {Checked = "checked"} : null) Maintenance
@if (Model.IsReady == true)
{
    <span> @Html.RadioButtonFor(model => model.StatusId, "1",Model.StatusId == '1' ? new {Checked = "checked"} : null) Active</span>
}
@Html.RadioButtonFor(model => model.StatusId, "2",Model.StatusId == '2' ? new {Checked = "checked"} : null) Inactive

那么如何在编辑模式下获得选中的单选按钮呢?

提前感谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-08 07:18:58

我制作无线电按钮的方式如下:

代码语言:javascript
复制
@Html.RadioButtonFor(model => model.StatusId,3,new { id = "rbMaintenance" })
@Html.Label("rbMaintenance","Maintenance")
@Html.RadioButtonFor(model => model.StatusId,2,new { id = "rbInactive" })
@Html.Label("rbInactive","Inactive")
@Html.RadioButtonFor(model => model.StatusId,1,new { id = "rbActive" })
@Html.Label("rbActive","Active")

代码的不同之处在于,由于您的StatusId类型是Int,所以您应该将RadioButtonFor中的值作为整数输入,例如,用于维护而不是'3‘。

票数 26
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23534642

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档