I m new to MVC, so maybe this is a stupid question - I m trying to get my head around strongly typed views in asp.net mvc. I m working on version 3. If I have a project with 2 models - say Person and Department. A person must belong to a department. So I have my Department model (and I ve generated my controller and CRUD interface):
public class Department
{
public int Id { get; set;}
public string DeparmentName { get; set;}
}
Then I have a Person model which references Department:
public class Person
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public int Department_Id { get; set; }
[ForeignKey("Department_Id")
public virtual Department Department { get; set;}
}
我现在提出我的主计长和看法。 现在,当我看一下个人主计长时,我有以下工作:
public ActionResult Create()
{
ViewBag.Department_Id = new SelectList(db.Deparments, "Id", "DepartmentName");
return View();
}
而在《个人法典》中,《创建部门法》下降。
@Html.DropDownList("Department_Id", String.Empty)
根据我的理解,DroopDownList Html的助手正在利用GisBag制作我的下级名单。 然而,第一民族和最后一个民族似乎在不依赖“观点”的情况下建立了自己的投入领域,因此,我认为,我本可以汇编时间,检查我的第一民族和最后一个民族领域,因为我的观点是严格分类的,而不是由我的德洛普·德南德斯。
是否有理由说明为什么对各省的DroopDownList没有大打字,或者我是否做过错,并且有办法使它严格分类?
Thanks :)