Home > DeveloperSection > Articles > RadioButton control in MVC

RadioButton control in MVC

0 Comment(s)
 25340  View(s)
Rate this:

RadioButton control in MVC

Here I am explaining how to create RadioButton Control in MVC and get the selected radio button reference.

Here in an Index View I have created various radio buttons that displays web technologies name by using Html Helper. In first parameter of radio button I passed a name of radio button and in second parameter I have passed its value that is similar to its text.
I have also created a submit button and on click of that submit button we get the value of selected radio button.

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<RadioButtonListMVC.Models.GenModel>" %>


<!DOCTYPE html>



<head runat="server">




<% using (Html.BeginForm("Show","Home",FormMethod.Post)) { %>

    <div><b>Select Technology: </b>

        <%= Html.RadioButton("technology", "ASP.NET") %> ASP.NET

        <%= Html.RadioButton("technology", "PHP") %> PHP

        <%= Html.RadioButton("technology", "JSP") %> JSP

        <%= Html.RadioButton("technology", "ASP.NET MVC") %> ASP.NET MVC

        <br /><br />

        <input type="submit" value="Submit" />


    <%} %>



After creating radio button in View, you can retrieve the reference of selected radio button with the help of Controller. Here in a Controller I have created a Show action that invoke when a submit button is pressed and when Show action invoked it retrieve the reference of selected radio button and the store its value in a string and then return a formatted string.

using System.Web.Mvc;

using RadioButtonListMVC.Models;


namespace RadioButtonListMVC.Controllers


    public class HomeController : Controller


        public ActionResult Index()


            return View();




        public string Show(FormCollection form)


            string selectedTechnology = form["technology"];

            return "You have selected a technology: <b>"+selectedTechnology+"</b>";




After performing the above task you can see an output in browser that displays list of radio button. You can select one of them.

RadioButton control in MVC

After selecting the choice when you press submit button, the browser will show you the value of selected radio button.

RadioButton control in MVC
By completing the above process you can simply learn that how to create radio button group or list and how to get a selected value from the list of radio button in MVC.

Don't want to miss updates? Please click the below button!

Follow MindStick