asp.net-mvc - RadioButtonFor helper 创建具有相同 id 的按钮,但我想应用 JQuery

标签 asp.net-mvc razor

我使用 Razor 3 单选按钮创建:

@Html.RadioButtonFor(model => model.SelectType, "Checking")
@Html.RadioButtonFor(model => model.SelectType, "Funds") 
@Html.RadioButtonFor(model => model.SelectType, "MoneyMarket")

Razor 创建了以下 HTML:

<input id="SelectType" name="SelectType" type="radio" value="Checking" /> 
<input id="SelectType" name="SelectType" type="radio" value="Funds" /> 
<input id="SelectType" name="SelectType" type="radio" value="MoneyMarket" /> 

现在我想使用 JQuery 隐藏一些选项,具体取决于选中的 RadioButton。我不能这样做,因为每个单选按钮都有相同的 ID。 有什么想法可以解决这个问题吗?

谢谢

z

最佳答案

正如tymeJV所说,只需手动分配id

@Html.RadioButtonFor(model => model.SelectType, "Checking", new { id = "rbChecking" })

关于asp.net-mvc - RadioButtonFor helper 创建具有相同 id 的按钮,但我想应用 JQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19038334/

相关文章:

c# - 无法将 List<T> 发布到 Controller

html - 我的 @Html.Partial 不在我的 _Layout.cshtml 中

javascript - 如何使用 RedirectToAction 传递 viewbag

c# - Sitecore 的 Field.HasValue 返回 false,即使有值?

asp.net-mvc - URL 包含 "&"返回内部服务器错误

c# - 使用 SqlCommand 从多个表中删除

C# MVC 更改启动页

c# - 是否可以使用maproute在asp.net mvc中路由多个参数

c# - 如何在 <img> src 标签中连接两个字符串?

c# - 单击 MVC3 Razor 中的提交按钮后在标签中显示测试框文本