我是MVC的新手,尤其是Visual Basic。在C#中查找各种单选按钮的在线示例后,我仍然无法看到它转换为VB。
任何人都可以帮助解决如何通过单选按钮传递值的简单说明。这只是简单地传递一个整数0,1或2等。然后我会在我的控制器中做一个if else来处理它。
我一直在尝试这样的事情
@Html.RadioButton("ButtonName", "1", True)
然后我想在控制器中选择它,如
Dim selection As Integer = ...
If selection == 1 Then
etc...
对不起的解释语法感到抱歉。简单来说就是
<input type="radio" name="SomeName" value="1">
<input type="radio" name="SomeName" value="2">
然后取回已检查的值。
非常感谢
答案 0 :(得分:1)
假设您的模型
public class YourModel{
int RadioValue{get;set;}
....
}
您的观点
@using namspace;
@model YourModel
@using(Html.BeginForm(....)){
@Html.RadioButton("RadioValue", 1, True) @* The first parameter is name, and must match the name of the property you are binding to. *@
@Html.RadioButton("RadioValue", 2, False)
}
您的控制器
public ActionResult(YourModel model)
{
//Get value
model.RadioValue....
}