Click here to Skip to main content
15,881,849 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to bind dropdownlist from database in C# MVC razor code?

Thank You.
Posted

Syntax:
C#
@Html.DropDownList(<drodownlist name="">, IEnumerable Selectlist, html Attribute) </drodownlist>


Ex:-
C#
@Html.DropDownList("lstGroupName", ViewBag.GroupName as MultiSelectList, new { @class = "groupDropdownlist" })


In these I am bind a list into that views controller & assign it to to the viewbag "GroupName".

In these if you have any question, Please let me know.
 
Share this answer
 
in view

@Html.DropDownList("dropDownName",(SelectList)ViewBag.Category, "--Select category--", new { @class = "ClassName" })


in controller

ViewBag.Category= new SelectList(dbEntities.Categories, "id", "category");// select statement in ef


hope this help. please vote if helped.

regards
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900