Click here to Skip to main content
15,907,906 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
@Html.DropDownListFor(Function(model) model.nDepartmentID, New SelectList(ViewBag.txt, "Value", "Text"), New With {Key .[class] = "select1",Key .style = "width: 150px;"})
Posted
Comments
Manish Pawar 12-Feb-15 3:58am    
Html.DropDownListFor(Function(model) model.nDepartmentID, New List(Of SelectListItem)() From {New SelectListItem() With {.Value = "0", .Text = "Plese Select one Item"}}.Concat(model.nDepartmentID.[Select](Function(model) New SelectList(ViewBag.txt, "Value", "Text")))) will this work

This can be achieved by a ViewModel.
At first you add your static value to this
an then add the model data from the database.

In your view you must use your ViewModel as model.
 
Share this answer
 
@Html.DropDownListFor(m => m.nDepartmentID, (SelectList)ViewBag.DepartmentList, "Select Any Department", new {@class="select1",@style="width: 150px;" })

public ActionResult ShowPage()
{
var deptmnts=db.Departments.ToList();
ViewBag.DepartmentList=new SelectList(deptmnts,"ID","DepartmentName");
retun View();
}
 
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