I am using ViewModel to create view in my asp .net MVC application. In this view I need to bind a dropdownlist (Successfully binded). Problem: I want to add extra items with value in dropdownlist like "select","0"
Here is my Viewmodel:
public class PagesViewModel
{
public int Id { get; set; }
[Required]
[Display(Name = "Page Name")]
public string PageName { get; set; }
[Display(Name = "Parent Page")]
public IEnumerable<Page> Page { get; set; }
}
My Controller:
public ActionResult Create()
{
var model = new PagesViewModel
{
Page = db.Pages.Where(s => s.IsActive == true).OrderBy(r => r.PageName)
};
//--- Here I need to add extra items manually
return View(model);
}
My View:
@Html.DropDownListFor(model => model.Id, new SelectList(Model.Page, "Id", "PageName"), "Select Parent Page", htmlAttributes: new { @class = "form-control" })