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 に答える