我做了一个简单的mvc 3网站。它工作正常,但数据库和类是凌乱的,因为我需要做下拉列表,我不知道如何实现使用不同风格的下沉列表。Mvc代码第一款
这里的东西怎么看起来像:
public class Departments
{
public int ID {get; set;}
...
}
public class Users
{
public int ID {get; set;}
...
public Department Dept {get; set;}
public List<Department> DeptList {get; set;}
public string SelectedDept {get; set;}
}
然后我用DropDownListFor帮手。可悲的是,我对这个代码的第一件事是新的。所以,现在我在数据库中得到了这两个额外的不必要的列。任何其他方式来做这个更清洁/更好?
感谢您的提示。对于字符串SelectedDept,它是@ Html.DropDownListFor(model => model.SelectedDept,new SelectList(Model.DeptList,“Value”,“Text”))。任何样本的帮手下拉列表? – Bahamut
使用类似于@ Html.DropDownListFor(x => x.DeptId,new SelectList(ViewBag.DeptList,“DerparmentName”,“id”),“Choose:”) – Daveo