我的dropDownListFor正确显示数据但是当我转到HttpPost时显示错误System.NullReferenceException。
我的viewModel:
public class contaModel
{
public SelectList responsaveis { get; set; }
public List<int> idResponsaveis { get; set; }
public SelectList responsaveisCartao { get; set; }
public List<int> idResponsaveisCartao { get; set; }
}
我在选择列表中输入日期的那一刻:
public ActionResult Create()
{
contaModel model = new contaModel();
model.responsaveis = new SelectList(db.responsavelporconta, "IdResponsavelPorConta", "Nome");
model.responsaveisCartao = new SelectList(db.responsavelporconta, "IdResponsavelPorConta", "Nome");
return View(model);
}
生成错误的行:
@Html.DropDownListFor(x => x.idResponsaveis, Model.responsaveis)
我使用List,因为我在页面中处理多个下拉列表。