Get Text of selected Radio Button in ASP.NET MVC
File => New Project
Templates => Visual C# => ASP.NET MVC 4 Web Application
Controllers => Add Controller=> Add
using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.Mvc;
namespaceMvcApplication1.Controllers
{
publicclassHomeController: Controller
{
//
// GET: /Home/
publicActionResultIndex()
{
returnView();
}
publicstringCheckRadio(FormCollectionfm)
{
stringgenRad = fm["Gender"].ToString();
return"Selected gender is "+ genRad;
}
}
}
Add View => Add
@{
ViewBag.Title = "Index";
}
h2>Indexh2>
@using(Html.BeginForm("CheckRadio", "Home", FormMethod.Post ))
{
div>
Select Gender:br/>
Male @Html.RadioButton("Gender", "Male")
Female @Html.RadioButton("Gender", "Female")
@*or you can use below syntax for radio buttons
Male
Female*@
div>
inputtype="submit"value="Submit"/>
}