c# - How to put a value in dropdown using records from database -


i want put value database because dropdown have value same text want separate or different value text. example code = 1, text = pathologist.

my controller:

public actionresult mainhistopathologyform(string id) {     var patientprofileviewmodel = new mdhpistables();     patientprofileviewmodel.histopathology = db.histopathology.find(id);     patientprofileviewmodel.roles = db.roles.find(session["role"]);     var pathologistlist = new list<string>();      var pathologistqry = d in db.pathologist                    select d.pathologist;      pathologistlist.addrange(pathologistqry.distinct());     tempdata["pathologistlist"] = new selectlist(pathologistlist);      return view(patientprofileviewmodel); } 

mainhistopathologyform.cshtml:

@html.partial("roleshistopathologyform", model.roles, new viewdatadictionary())   @html.partial("partial_histopathologyform", model.histopathology,  new viewdatadictionary()) 

partial_histopathologyform:

@{     viewbag.concurring1 = tempdata["pathologistlist"];  }                             @html.dropdownlist("concurring1", "select pathologist")   

@html.dropdownlist("your viewbag name", null, "select list", new { @class = "form-control", required = "required" })


Comments