MVC3: Set Dropdown list Selected Value

左心房为你撑大大i 提交于 2019-12-05 10:14:04

Extending on what Romias said, in your controller, set Model.State to whatever value you want. If you wanted 'WI', then Model.State should equal that.

Controller:

public ActionResult Index()
{
    var m = new TestViewModel();
    m.State = "WI";
    return View(m);
}

View:

@Html.DropDownListFor(m => m.State, new SelectList(Model.StateList, "Value", "Text", Model.State))

Just do:

@Html.DropDownListFor(m => m.State, new SelectList(Model.StateList, "Value", "Text", Model.State))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!