1

我的场景是好的我有一个多选列表框,我想要的是当我们选择多个记录并按下按钮时,我应该在控制器的调用方法中选择项目列表。我的代码在下面

csthml 代码:

@{
 Layout = "";
}
@using Telerik.Web.Mvc.UI;
@using System.Web;
@using System.Web.UI.WebControls;
@using System.Web.Mvc;

@model Nop.Plugin.Import.Product.Models.ImportProductModel
<div>
<div class="section-header">
    <div class="options">            
    @using (Html.BeginForm("ImportSelected",  "ImportProduct"))
    {
        <button type="submit">OK</button>
    }
    </div>
 </div>

 <table>
    <tr>
        <td>
            @Html.ListBox("Items", Model.nopCommerceCategories);
        </td>

        <td>
            @Html.ListBox("Items", Model.ClockCategories);
        </td>
    </tr>
    <tr>
        <td>
                @using (Html.BeginForm("SaveMapping", "ImportProduct"))
                {
                    <button type="submit">Save</button>
                }
        </td>
    </tr>
  </table>        
 </div>

模型 :

using System.Collections.Generic;
using System.Web.Mvc;
using Nop.Core.Domain.Catalog;

namespace Nop.Plugin.Import.Product.Models
{
    public class ImportProductModel
    {        
        public List<SelectListItem> nopCommerceCategories { get; set; }
        public List<SelectListItem> ClockCategories { get; set; }
    }
}
4

2 回答 2

0

你的表单里面只有一个提交按钮,你应该把你的列表框放在一个表单中,当表单提交时,列表框的值和表单内的所有其他内容都将发送到表单指向的操作

于 2013-04-10T13:02:30.307 回答
0

注意:列表框的第一个参数是您要发送到控制器的名称!因此,您应该使用这样的代码:

@Html.ListBox("nopCommerceCategories", Model.nopCommerceCategories);
@* or this code :
@Html.ListBoxFor(model => model.nopCommerceCategories);
*@

然后当您使用以下签名调用您的控制器时:

 public ActionResult SaveMapping(ImportProductModel ipm) {
     // here you have access to ipm.nopCommerceCategories
 }

此外,您必须将所有代码与您想要以一种形式获取的数据一起封装!如果您想提交多个操作,请添加一个 javascript 代码以检索正确的操作以提交您的数据...

于 2013-04-10T13:00:12.210 回答