In this article,I will talk about how to use radio button in asp.net MVC.
To begin with open Visual Studio 2008 and choose File > New > Project > ASP.NET MVC.The first thing to do is to create a class that will be the structure of our data to fill radio button.Add new class to the project and name it RadioOption.Add the following code to the RadioOption class:
I will create a controller and name it RadioListController for this example. In the constructor of controller,following code to add data to List<RadioOption>
In method Get of action Create,following code to return a list of RadioOption to view for fill data to radio button.
In RadioListController,right click,choose Add View to genarate View of action,in the top of View,fill this code:
And following code to genarate radiobutton.
In method Post of action Create,fill this code:
"return RedirectToAction("Create", new { valueOfRadio = radio.ToString() });" to return value of radio button be selected to View of method Get of action Create to check value of radio be choose.
To do that,add this command to method Get of action Create.
ViewData["valueOfRadio"] = valueOfRadio;
This is full code of RadiolistController.cs
This is full code of View Create.aspx
Looking forward feedback from you!
8a02621e-8e2f-4699-8acf-61942ec9baff|0|.0