Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 具有逗号分隔值的Ajax post字典_Jquery_Ajax_Asp.net Core - Fatal编程技术网

Jquery 具有逗号分隔值的Ajax post字典

Jquery 具有逗号分隔值的Ajax post字典,jquery,ajax,asp.net-core,Jquery,Ajax,Asp.net Core,我有一本字典如下 var selectedKeys = { "bu": bu_keys, "be": be_keys, } bu_键、be_键每个键都有一个用逗号分隔的字符串。 例子: bu_键的可能值为:“12354,abccsd,dsdfdlk,d35487” 当我把它发送给我的控制器时,我只得到了字符串的第一部分,即12354 $.ajax({ url: "@Url.Action("Download", "Reports")",

我有一本字典如下

var selectedKeys = {
        "bu": bu_keys,
        "be": be_keys,
    }
bu_键、be_键
每个键都有一个用逗号分隔的字符串。 例子: bu_键的可能值为:“12354,abccsd,dsdfdlk,d35487” 当我把它发送给我的控制器时,我只得到了字符串的第一部分,即12354

$.ajax({
        url: "@Url.Action("Download", "Reports")",
        dataType: "json",
        type: "POST",
        data: { allKeys: selectedKeys },
        success:  function (selectedKeys) {
            //do nothing
        },
        error: function (xhr, status, error) {
            alert("Error: Please refresh the page and try again!" + status + " " + error + " " + xhr.status + " " + xhr.statusText);
        }
    });
public FileResult DownLoad(Dictionary<string, string> allKeys)
    {
      // code here

    }

    public FileResult DownLoad2(Dictionary<string, string[]> allKeys)
    {
        // code here
    }
$.ajax({
url:“@url.Action”(“下载”、“报告”)”,
数据类型:“json”,
类型:“POST”,
数据:{allKeys:selectedKeys},
成功:功能(选择键){
//无所事事
},
错误:函数(xhr、状态、错误){
警报(“错误:请刷新页面并重试!”+status+“”+Error+“”+xhr.status+“”+xhr.status text);
}
});
公共文件结果下载(字典所有键)
{
//代码在这里
}
公共文件结果下载2(字典所有键)
{
//代码在这里
}

如何获取所有字符串不仅是字符串的第一部分,我还尝试了操作下载和下载2,但都没有成功

您可以通过json类型传递数据。以下代码示例供您参考:

var selectedKeys = {
    "bu": "12354,abccsd,dsdfdlk,d35487",
    "be": "12354,abccsd,dsdfdlk,d35487",
    }

$.ajax({
    url: '/Download/Reports',
    dataType: "json",
    type: "POST",
    data: JSON.stringify(selectedKeys),
    contentType: 'application/json; charset=utf-8',
    success:  function (selectedKeys) {
        //do nothing
    },
    error: function (xhr, status, error) {
        alert("Error: Please refresh the page and try again!" + status + " " + error + " " + xhr.status + " " + xhr.statusText);
    }
});
控制器:

public IActionResult Reports([FromBody]MyModel myModel)
{
    ....
    return Json("OK");
}

public class MyModel { 
    public string bu { get; set; }
    public string be { get; set; }
}

data:{allKeys:selectedKeys}
应该是:
data:selectedKeys