Dropdownlist with inline selectlist in MVC 5

In this post we will learn how to implement dropdownlist with inline selectlist in MVC 5.

lets start by creating action method in controller

Action Method
public ActionResult Index2(string gender)
    ViewBag.gender = gender;
    return View();


add a view for this action method and write the following code

    ViewBag.Title = "Dropdownlist with inline selectlist || Chikkanti.wordpress.com";

<h2>Dropdownlist with inline selectlist</h2>

@using (Html.BeginForm())
    @Html.Label("Gender : ")
    @Html.DropDownList("gender", new SelectList(new List<SelectListItem>() {
    new SelectListItem(){Text="Male", Value="Male"},
    new SelectListItem(){Text="Female", Value="Female"}
    }, "Value", "Text", "..Select.."))
    <input type="submit" name="name" value="Submit" />
    if (!string.IsNullOrEmpty(ViewBag.gender))
        string message = "Selected Gender : " + ViewBag.gender;


Now Rebuild the application and run



Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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