选择多个不发布值

时间:2017-07-13 16:55:08

标签: html asp.net asp.net-mvc asp.net-mvc-5

我遇到ASP.NET MVC无法识别选择多个项目的问题。我正在渲染以下多选:

<select name="@Html.NameFor(m => m.Items[index].GroupIDS)" class="group-id" multiple="multiple">
   @if (entity.Groups != null)
   {
      foreach (var grp in entity.Groups)
      {
         <option value="@grp.ID" selected="selected">@grp.Description</option>
      }
   }
</select>

我无法使用Html.ListBoxFor,因为我的设置稍微复杂一些。它在回发之前呈现如下:

<select name="Items[0].GroupIDS" class="group-id init" multiple="multiple">
      <option value="3" selected="">Item 1</option>
      <option value="4" selected="">Item 2</option>
</select>

我正在尝试回复集合中的属性,定义如下(在模型上):

   //ViewModel
     //Items collection - that object has a property of:
        public long[] GroupIDS { get; set; }

当POST发生时,以下是Request.Forms集合返回的内容。如果选择了多个项目,则根本不会返回任何内容(下面是Request.Forms.AllKeys集合):

[23]: "Items[0].ID"
[24]: "Items[0].GroupIDS" -- Only 1 item returned; [1] and [2] have more than 1
[25]: "Items[0].IsDeleted"
[26]: "Items[1].ID"
[27]: "Items[1].IsDeleted"
[28]: "Items[2].ID"
[29]: "Items[2].IsDeleted"

知道为什么吗?

1 个答案:

答案 0 :(得分:1)

模型绑定器无法绑定到数组。您需要select * from openquery(diffserver,'select name,object_id,definition from dbname.sys.default_constraints') 属性,例如:

IList
相关问题