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;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.Mvc;
namespace
MvcApplication1.Controllers
{
public
class
HomeController
: Controller
{
//
//
GET: /Home/
public
ActionResult
Index()
{
return
View();
}
public
string
CheckRadio(FormCollection
fm)
{
string
genRad = fm["Gender"].ToString();
return
"Selected
gender is "
+ genRad;
}
}
}
Add View => Add
@{
ViewBag.Title
= "Index";
}
<h2>Index</h2>
@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<input
type="radio" name="gender" value="Male"/>
Female<input
type="radio" name="gender" value="Female"
/>*@
</div>
<input
type="submit"
value="Submit"/>
}
Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging…
ReplyDeleteRegards,
Dot Net coaching Institute in Chennai | Dot Net Training in Chennai | Dot Net Training Center in Chennai
Software Testing Training Institute in Chennai | Manual Testing Training in Chennai | Testing Courses in Chennai
Java Training Institute in Chennai | Java Course and Certification | Core Java Certification in Chennai
PHP Certification Class | PHP Course in Chennai | PHP Training Institute in Chennai