【发布时间】:2014-08-07 22:11:35
【问题描述】:
在 MVC Radiobuttonfor helper 中使用以下表示法,我可以创建一个单选,如果模型中存在值,则该单选将选择默认按钮。
@Html.RadioButtonFor(x => x.Username, "Y", Model.Username == "Y" ? new { Checked = "checked", id = "YUserName" } : null) No:
@Html.RadioButtonFor(x => x.Username, "N", Model.Username == "N" ? new { Checked = "checked" } : null)
但是id = "YUserName" 不适用于值为“Y”的单选按钮
如果我在radiobuttonfor helper 中没有评估表达式,我可以用值“Y”更改收音机的id,即:
@Html.RadioButtonFor(x => x.UsePriorFinancialInfo, "Y", new { id = "YUsePriorFinancialInfo" })
@Html.RadioButtonFor(x => x.UsePriorFinancialInfo, "N")
有没有办法使用评估表达式将自定义 ID 应用于其中一个单选按钮?如果没有,如果选择了任一单选按钮,是否有办法触发 jQuery 函数? - 谢谢
【问题讨论】:
标签: jquery asp.net-mvc html-helper radiobuttonfor