Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Get Text of selected Radio Button in ASP.NET MVC

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"/>
}




This post first appeared on Asp.netSourceCodes, please read the originial post: here

Share the post

Get Text of selected Radio Button in ASP.NET MVC

×

Subscribe to Asp.netsourcecodes

Get updates delivered right to your inbox!

Thank you for your subscription

×