如何将多个选定值传递给控制器​​?

时间:2019-09-10 08:50:46

标签: javascript ajax asp.net-mvc kendo-ui kendo-multiselect

我已将剑道下拉列表转换为剑道多选。我想将多个选择的值传递给控制器​​。

Dropdownlist包含:

  1. D-UDMS-TMA数据管理系统
  2. U-TDMS-SMA管理系统

以下是我的代码:

<input type="date">

注释行用于Dropdownlist。

我正在将多个(已选择,即Rolecode和MPID)值传递给控制器​​的Headerdetails。

以下是我的控制器调用:

$("#btnSendFlow").click(function () {

            debugger;

            var FlowData_array = [];

            //var ROLECODE = $("#DDRolecode").val().trim();---For dropdownlist output: "D"
            var ROLECODE = $("#DDRolecode").data("kendoMultiSelect").value();//added by chetan for multiselect output: "D" "U"

            // var MPID = $("#DDRolecode").data("kendoDropDownList").text().split('-');---for dropdownlist output: (3)["D","UDMS","TMA Data Mgmt System"]

            var control = $("#DDRolecode").data("kendoMultiSelect");
            var selectedDataItems = control.dataItems();

            //// create an array that only contains the selected ids
            var MPID = [];
            $(selectedDataItems).each(function () {
                MPID.push(this.Name.split('-')); // you can access any property on your model here
            });
            console.log(MPID);

            //
            output for MPID while debugging:
            (3)["D","UDMS","TMA Data Mgmt System"] which is 0: Array(3)
                                                              0: "D"
                                                              1: "UDMS"
                                                              2: "TMA Data Management Ltd"
                                                              length: 3
            (3)["U","TDMS","SMA Mgmt System"] which is 1: Array(3)
                                                          0: "M"
                                                          1: "BMET"
                                                          2: "Bglobal NHH MOP"
                                                              length: 3

            length:2
            //
        .....
        .....

         MstHeaderData = {
            REG_ID: $("#hfRegid").val(),
            DataFlow_ID: $("#DDDataFlow").val(),
            RoleCode: ROLECODE,//How to to do for the multiselect values.
            //RoleCode: ROLECODE.trim(),//for dropdownlist
           // MPID: MPID[1] //for dropdownlist
            MPID: MPID// How to do for the multiselect values
        }
        }

类文件:

 public ActionResult SaveSendFlowDetails(Temp_Flow_Generation_Item[] SSFD,HeaderDetails HeaderDetails, FormCollection form)
         {
         ....
         .....
         }

2 个答案:

答案 0 :(得分:2)

尝试将模型属性MPID更改为:

public string[][] MPID { get; set; }

由于您的数据是字符串数组的字符串数组,又称为字符串矩阵。

答案 1 :(得分:1)

我使用了下面的代码,并且有效:

 for (i = 0; i < MPID.length; i++) {


            MstHeaderData = {
                REG_ID: $("#hfRegid").val(),
                DataFlow_ID: $("#DDDataFlow").val(),
                RoleCode: MPID[i][0],
                //RoleCode: ROLECODE.trim(),
                // MPID: MPID[1]
                MPID: MPID[i][1]
            }


            var url = '@Url.Action("SaveSendFlowDetails", "FlowGenerator")';
            .....
            .....
}