lundi 30 mars 2015

Modify Dropdown list in asp.net mvc


Vote count:

0




I'm using dropdown menu to filter available and not available books. Right now when the page loads the whole list of books is displayed then I filter the list based on the availability using the bool value. I want to modify the text that displays in the dropdown menu, because right now it is "true" and "false". And I also don't know how to add option in the dropdown menu to display the whole list. So that dropdown menu would have options to view whole list, available books and not available books.


Controller:



public ActionResult IndexBookReport(bool ? avail = null)
{
ViewBag.avail = (from book in Database.Session.Query<Book>() select book.IsAvail);
var bookList = new ReportList()
{
Book = from b in Database.Session.Query<Book>()
orderby b.NumId
where b.IsAvail == avail && avail != null || avail == null
select b
};

return View(bookList);
}


Razor:



@using (Html.BeginForm())
{
<text>Books</text>@Html.DropDownList("avail", new SelectList(ViewBag.avail))

<input type="submit" value ="Filter"/>
}


Any help would be appreciated



asked 1 min ago







Modify Dropdown list in asp.net mvc

Aucun commentaire:

Enregistrer un commentaire