【发布时间】:2015-06-10 18:09:57
【问题描述】:
我正在使用 ASP.NET MVC 5 开发一个网站,并使用 Chosen.js 进行多项选择。我的操作是这样的:
[HttpGet]
public ActionResult Get()
{
var states = GetStates();
ViewBag.States = new SelectList(states.OrderBy(o => o.Id), "Value", "Name");
return View();
}
在视图中:
@Html.ListBoxFor(m => m.States,
ViewBag.States as SelectList, new Dictionary<string, object>
{
{"multiple", "multiple"},
{"class", "chosen-container-multi"},
{"placeholder", "State"},
{"id", "State"}
});
它工作正常,但我想在加载页面之前预先选择用户状态。可能是这样的:
ViewBag.States = new SelectList(states.OrderBy(o => o.Id), "Value", "Name","UserStateId");
但它不起作用。有没有办法做到这一点?
【问题讨论】:
标签: jquery asp.net asp.net-mvc jquery-chosen