1

当我提交时,我得到的 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; }
4

1 回答 1

0

我在这里找到了正确的解决方案@Html.DropDownList 选择值问题

所以在我的情况下应该是这样的:

   <div style="display: inline-block;">@Html.DropDownListFor(x => x.Common.StateID, Model.Common.StateList, "-- Select --",  new { style = "width: 130px;" })</div>
于 2012-11-14T11:53:33.430 回答