如何显示在Asp.Net MVC3使用单选按钮 [英] how to show and use Radio button in Asp.Net MVC3
本文介绍了如何显示在Asp.Net MVC3使用单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在我的Asp.Net MVC3 App.There两个单选按钮是在我的数据库重新presenting这些单选按钮没有现场。
所以我不能使用它们这样
I want to have two radio buttons in my Asp.Net MVC3 App.There is no field in my Database representing these Radio button. So i cant use them this way
@Html.LabelFor(model => model.Monthly)
@Html.EditorFor(model => model.Yearly)
我试图用这个来证明我的单选按钮
I have tried to use this to show my radio button
@Html.Label("Monthly","Monthly")
@Html.RadioButton("Monthly","Monthlyy")
@Html.Label("Yearly","Yearly")
@Html.RadioButton("Yearly","Yearly")
的按钮是可见的,但用户可以选择这两个按钮together.Whereas我想,只有一个按钮可以一次进行检查。
此外,我将需要检查的单选按钮的标签我App.How进一步的功能,我可以添加的单选按钮,我怎样才能得到检查单选按钮的标签(文本值)。
请指导如何实现这一点。
Please guide how to achieve this.
推荐答案
有关你能够组单选按钮,他们需要有相同的名称。即。
For you to be able to group the radio buttons, they need to have the same name. i.e.
<input type="radio" name="group1" value="No"/>
<input type="radio" name="group1" value="Yes"/>
<input type="radio" name="group2" value="No"/>
<input type="radio" name="group2" value="Yes"/>
所以你的情况,你想要做什么是以下
So in your case, what you want to do is the following
@Html.Label("Monthly")
@Html.RadioButton("MonthlyOrYearly", "Monthly")
@Html.Label("Yearly")
@Html.RadioButton("MonthlyOrYearly", "Yearly")
这篇关于如何显示在Asp.Net MVC3使用单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文