Radiobuttonlist in MVC 5 using Model, Radiobuttonlistfor

In this post we are going to learn how to implement radiobuttonlist in mvc 5 with model using html helper radiobuttonlistfor


First add a model and a property called Gender as follows

public class GenderModel
        public string Gender { get; set; }



Add a controller and a action method in it as follows

public ActionResult RdBtnList(GenderModel model)
            return View(model);


in this action method we are passing empty model to view in get call, and we will pass model with data in post call.


@model MVCControls.Models.GenderModel
    ViewBag.Title = "Radio Button List using Model ||";

<h2>Radio Button List using Model</h2>
@using (Html.BeginForm())
    @Html.RadioButtonFor(g => g.Gender, "Male")@Html.Label("Male")
    @Html.RadioButtonFor(g => g.Gender, "Female")@Html.Label("Female")
    <br />
    <input type="submit" value="Submit" /><br />
    if (!string.IsNullOrEmpty(Model.Gender))
        @Html.Label("Your selected option: " + Model.Gender);


Now Rebuild your application and run the application.





Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s