【问题标题】:How to pass multiple selected values to controller?如何将多个选定的值传递给控制器​​?
【发布时间】:2020-01-11 23:58:17
【问题描述】:

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

下拉列表包含:

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

以下是我的代码:

$("#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
        }
        }

注释行用于下拉列表。

我将多个(选定的,即角色代码和 MPID)值传递给控制器​​的 Headerdetails。

以下是我的控制器调用:

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

类文件:

public class HeaderDetails
          {
        public int REG_ID { get; set; }
        public int DataFlow_ID { get; set; }
        public string RoleCode { get; set; }
        public string MPID { get; set; }
         }

【问题讨论】:

  • this.Name 是什么,从何而来?
  • @BrianMains 这是一个多选参数 ID 和名称

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


【解决方案1】:

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

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

由于您的数据是字符串数组的字符串数组,也就是字符串矩阵。

【讨论】:

    【解决方案2】:

    我已经使用了下面的代码并且它有效:

     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")';
                .....
                .....
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-07-27
      • 2011-09-25
      • 2016-09-10
      • 2021-11-12
      • 1970-01-01
      • 2015-12-18
      • 2017-11-30
      相关资源
      最近更新 更多