How to bind MVC dropdown list
am new to mvc frame worki need an help to work with dropdownlist please help me
public class DsrModel
{
//Fill the coulmns
}
public class BindingController:Controller
{
public ActionResult BindingDD()
{
List<selectedListItem> lst = new List<selectedListItem>();
// We can fill this list by adding the values from the list or we can get the values from Database.
}
}
<%= Html.DropDownList("SelectedItem", Model.ListItems,"-----Select----") %>
@Html.DropDownList("SelectedStoreType", (IEnumerable<SelectListItem>)ViewBag.StoreType)
Code for control action public ActionResult SelectStore()
{
List<SelectListItem> items = new List<SelectListItem>();
items.Add(new SelectListItem { Text = "MyStore1", Value = "MyStore1", Selected=true });
items.Add(new SelectListItem { Text = "MyStore2", Value = "MyStore2" });
var model = new MyViewModel
{
MovieTypes = items
};
return View(model);
}