当我提交时,我得到的 StateID 总是空的。
任何线索我在这里想念什么?
谢谢你!
HTML:
<div style="display: inline-block;">@Html.LabelFor(x => x.Common.StateID , new { @class = "SmallInput2" })</div>
<div style="display: inline-block;">@Html.DropDownList("StateID", Model.Common.StateList, "-- Select --", new { style = "width: 130px;" })</div>
代码:
public ActionResult SignUp()
{
var model = new SignUpModel
{
Common = new Common(),
Individual = new Individual(),
Business = new Business()
};
var stateList = new SelectList(_context.States.OrderBy(w => w.StateName), "ID", "StateName", _context.States.OrderBy(w => w.StateName).FirstOrDefault().ID);
model.Common.StateList = stateList;
model.Common.StateID = _context.States.OrderBy(w => w.StateName).FirstOrDefault().ID;
return View(model);
}
模型:
[Display(Name = "State")]
public Guid StateID { get; set; }
[Display(Name = "States")]
public SelectList StateList { get; set; }