开发者

Asp.Net MVC 3 ListBox will not select initial values

开发者 https://www.devze.com 2023-03-13 05:20 出处:网络
I am trying to set the initial values for a list box using asp.net mvc 3.It does fill in the options, but doesn\'t select them.

I am trying to set the initial values for a list box using asp.net mvc 3. It does fill in the options, but doesn't select them.

Here is my code. This attempt uses a hardcoded set of values

@Html.ListBoxFor(Function(model) model.PageTags, New MultiSelectList(Model.PageTags, "ID", "TagEn", New Integer(){1,2})

I have also tried an example that I would expect would select all the values.

@Html.ListBoxF开发者_JS百科or(Function(model) model.PageTags, New MultiSelectList(Model.PageTags, "ID", "TagEn", Model.PageTags)


You have to pass the selected values as an enumerable of "values" (and not an enumerable of the original "items"). In your case this should be a list of IDs. E.g. to select all try to pass the selected values like this: Model.PageTags.Select(i => i.ID)

0

精彩评论

暂无评论...
验证码 换一张
取 消