Reputation: 41
I am pretty new with MVC and especially with Visual Basic. After looking up all kinds of online examples for radio buttons in C# I still can't see it translating into VB.
Can anyone help out with a simple explanation on how to pas a value through a radio button. That is just simply pass an integer 0, 1 or 2 etc.. then I will do an if else in my controller to handle it.
I've been trying something like that
@Html.RadioButton("ButtonName", "1", True)
And then I want to pick that up back in the controller as in
Dim selection As Integer = ...
If selection == 1 Then
etc...
sorry for the bad explanation syntax. In plain words
<input type="radio" name="SomeName" value="1">
<input type="radio" name="SomeName" value="2">
Then get back the value that was checked.
Thank you so much
Upvotes: 0
Views: 945
Reputation: 525
Assume your model
public class YourModel{
int RadioValue{get;set;}
....
}
Your view
@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)
}
Your Controller
public ActionResult(YourModel model)
{
//Get value
model.RadioValue....
}
Upvotes: 1