Vb.net 单选按钮Visual Basic MVC 4

Vb.net 单选按钮Visual Basic MVC 4,vb.net,asp.net-mvc-4,Vb.net,Asp.net Mvc 4,我是MVC新手,尤其是Visual Basic。在查找了C语言中单选按钮的各种在线示例后,我仍然看不到它被翻译成VB 有人能帮我简单解释一下如何通过单选按钮获取值吗。这只是简单地传递一个整数0、1或2等。。然后我将在控制器中执行if-else来处理它 我一直在尝试类似的事情 @Html.RadioButton("ButtonName", "1", True) 然后我想在控制器中恢复它,就像在 Dim selection As Integer = ... If selection == 1 T

我是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"> 

然后返回已检查的值

非常感谢您

假设您的模型

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....
}

你的代码没有显示你是如何读回值的。在我的模型中,我声明了一个名为selection的整数。我想从单选按钮视图中传递一个整数。不确定代码在控制器中的外观。我也看过@Html.RadioButtonFor(函数(b)b.SelectedAnswer,b.ID)的这个,但是我想不出来。非常感谢!这就是我需要的,我会在早上试一试
@Html.RadioButtonFor
通常是更好的选择。