我遇到了关于MVC下拉列表的问题。我搜索过并搜索过但无济于事。
我的ViewModel
public class IncidentFormViewModel
{
public Guid Guid { get; set; }
public Incident Incident { get; set; }
public Guid PersonInvolvedId { get; set; }
public IEnumerable<Person> People { get; set; }
}
我的控制器
public ActionResult New()
{
var incidentFormVM = new IncidentFormViewModel
{
Incident = new Incident(),
People = unitofwork.Person.GetAll()
};
return View("IncidentForm", incidentFormVM);
}
和查看(我已经取出了无用的信息)
@using (Html.BeginForm("Save", "Incident"))
<div class="container">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
@Html.LabelFor(m => m.Incident.PersonInvolved)
@Html.DropDownListFor(m => m.PersonInvolvedId, new SelectList(Model.People, "Id", "FirstName"), new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.Incident.PersonInvolved)
</div>
</div>
<br />
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
问题是,如果我在下面的线上停下来,并在Model.People上观看我可以看到反对它的人员名单。
@Html.DropDownListFor(m => m.PersonInvolvedId, new SelectList(Model.People, "Id", "FirstName"), new { @class = "form-control" })
我做错了什么?