그래서 저는 StackOverflow를 많이 둘러보고 내 문제에 대한 좋은 해결책을 발견했습니다.DropDownList null 값, 사용 된 참조
MVC3 DropDownListFor - a simple example?이 작업은 저에게해야합니다. 하지만 null 값을 반환했습니다 ... 어떻게 든이 도움을받을 수 있도록이 문제를 해결하는 방법을 모릅니다. StateID = -1
어떤 이유로 널은 출력 만들어 내
모델 AccountModel.cs
...
public string Address { get; set; }
public string City { get; set; }
public class StateList
{
public int StateID { get; set; }
public string Value { get; set; }
}
public IEnumerable<StateList> StateListOptions = new List<StateList>
{
//new StateList { StateID = -1, Value = "Select State" },
new StateList { StateID = 0, Value = "NY" },
new StateList { StateID = 1, Value = "PO" }
};
public string State { get; set; }
public string Zip { get; set; }
...
Register.cshtml
@Html.DropDownListFor(m => m.State, new SelectList(Model.StateListOptions, "StateID", "Value", Model.StateListOptions.First().StateID))
나는 어쩌면 생각 ...하지만 그것을하지 않았다 , 당신은 그것이 여기에 주석 처리 된 것을 볼 수 있습니다. 내가 뭘 잘못 했니?!
가져 오기 작업
public ActionResult Register()
{
ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
return View();
}
GET 조치는 어떻게 생겼습니까? – Shyju
문제의 조치를 추가했습니다. – rexdefuror