Home ASP.NET MVC Select Option Value of SelectList
Reply: 0

ASP.NET MVC Select Option Value of SelectList

user754 Published in June 22, 2018, 11:31 am

I am rendering a dropdown list.

ViewBag.Categories = new SelectList(db.HelpCategories, "ID", "Name");

In my view I call it like this:

Categories: @Html.DropDownList("Categories", (SelectList)ViewBag.Categories, "All")

For which I get select values like this.

<select id="Categories" name="Categories">
   <option value="">All</option>
   <option value="1">Dėl Krepšelių</option>

I really need to set the value of "All" to 0. Can't figure out a way to do it. Found a tutorial that it's done with SelectListItem, but that doesn't fit my code. Any help is really appreciated, thank you.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.318025 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO