asp.net MVC的Html.RadioButton生成ID和名称相同 [英] Html.RadioButton of asp.net MVC generates id and name same

查看:486
本文介绍了asp.net MVC的Html.RadioButton生成ID和名称相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<%=Html.RadioButton("BookType", "1")  %> C#
<%=Html.RadioButton("BookType", "2")  %> VB

以上code产生以下code

Above code generates Below code

<input id="BookType" name="BookType" type="radio" value="1" >C#
<input id="BookType" name="BookType" type="radio" value="2" >VB

我需要的名称相同,但不同的ID

I need same name but different ids

我要像

*

<input id="rdoCSharp" name="BookType" type="radio" value="1" >C#
<input id="rdoVb" name="BookType" type="radio" value="2" >VB

*

推荐答案

您可以通过传递的属性覆盖默认你希望使用的的/library/dd492690.aspx\">overload:

You can override the defaults by passing the attributes you wish to apply using an overload of the RadioButton method:

<%=Html.RadioButton("BookType", "1", new { id = "yourId" })  %> C#

这篇关于asp.net MVC的Html.RadioButton生成ID和名称相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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