Dropdownlist control in MVC using HTML helpers

A dropdownlist in MVC is a collection of SelectListitem objects. Depending on your project requirement you may either hard code the values in code or retrieve them from a database table.

First here we show dropdownlist using hard coded value.

Write following code to your view.


DROPDOWNLIST

Now run application.(ctrl + F5).


DROPDOWNLIST

Now write code in Index action for retrieve data from database.

DROPDOWNLIST

Right click on Index action and Add View and write following code.

DROPDOWNLIST

Now run application.(ctrl + F5).

DROPDOWNLIST






Post a Comment