drop down menu - MVC5 DropDownList -
i trying create dropdownlist selection department, based on selected department table should filtered. kind of viewbag example here: http://www.codeproject.com/articles/687061/multiple-models-in-a-view-in-asp-net-mvc-mvc
//controller using system; using system.collections.generic; using system.data; using system.data.entity; using system.linq; using system.net; using system.web; using system.web.mvc; using ucontoso.models; namespace ucontoso.controllers { public class dashboardcontroller : controller { private univcontosoentities db = new univcontosoentities(); // get: /student/ public actionresult index() { var deptquery = db.faculties.include(f => f.department); return view(deptquery.tolist()); } protected override void dispose(bool disposing) { if (disposing) { db.dispose(); } base.dispose(disposing); } } } //model(department) namespace ucontoso.models { using system; using system.collections.generic; using system.componentmodel; public partial class department { public department() { this.courses = new hashset<course>(); this.faculties = new hashset<faculty>(); } public int departmentid { get; set; } [displayname("department")] public string departmentname { get; set; } public virtual faculty faculty { get; set; } public virtual icollection<course> courses { get; set; } public virtual icollection<faculty> faculties { get; set; } } } //model (faculty) namespace ucontoso.models { using system; using system.collections.generic; using system.componentmodel; public partial class faculty { public faculty() { this.courses = new hashset<course>(); this.courses1 = new hashset<course>(); } public int facultyid { get; set; } [displayname("faculty lastname")] public string lastname { get; set; } [displayname("faculty firstname")] public string firstname { get; set; } public system.datetime hiredate { get; set; } public virtual department department { get; set; } public virtual icollection<course> courses { get; set; } public virtual icollection<course> courses1 { get; set; } public int departmentid { get; set; } } } //view @model ienumerable<ucontoso.models.faculty> @{ viewbag.title = "index"; } <h2>index</h2> //dropdownlist doesn't work: should select department , filter table <p> @html.dropdownlist("department", "select") </p> <table class="table"> <tr> <th> @html.displaynamefor(model => model.department.departmentname) </th> <th> @html.displaynamefor(model => model.lastname) </th> <th> @html.displaynamefor(model => model.firstname) </th> </tr> @foreach (var item in model) { <tr> <td> @html.displayfor(modelitem => item.department.departmentname) </td> <td> @html.displayfor(modelitem => item.lastname) </td> <td> @html.displayfor(modelitem => item.firstname) </td> </tr> } </table>
Comments
Post a Comment