Radio Button List in Asp.Net MVC3 or MVC4
Hi Developers,
I
going to show the RadioButton List MVC3.How To bind and show the list in a view.
Model Property :
public string Gender { get; set; }
Employeee Controller :
Here I’m
creating a list of items to bind in drop down list and returning.
private List<SelectListItem> EmployeeGender()
{
var options = new List<SelectListItem>();
options.Add(new SelectListItem
{ Value = "Male", Text = " Male" });
options.Add(new SelectListItem
{ Value = "FeMale", Text = " FeMale " });
return options;
}
Suppose if want to create a some data regarding
employee gender details. In Controller directly u can assign into a some
ViewData or ViewBag or Session. so here I’m showing using ViewData how to bind
into particular list of items.
In contoroller u can call the
method and assign into a ViewDate like this :
ViewData["EmpGender"]
= new SelectList(EmployeeGender
(), "Value", "Text", Model Property Name);
So now I’m
going to show the view how to retrieve the Radio Button gender list.
View :
@Html.RadioButtonFor(model =>
model.BatActive, "Male", true)Male
@Html.RadioButtonFor(model =>
model.BatActive, " FeMale ", true)Female
Happy Coding...
Jagan Mohan
No comments:
Post a Comment