首页 > 解决方案 > 将数字数组从 JS 发送到 asp.net MVC 操作

问题描述

我想将数字数组发送到我的后退操作,无论我尝试什么,我都会得到 NULL 或错误。这是我当前的代码。

JS

$.ajax({
        traditional: true,
        dataType: "json",
        contentType: 'application/json; charset=utf-8',
        type: "POST",
        data: JSON.stringify(groupIds),
        url: '/Admin/ReadMessages',
        error: function (error) {
            swal.fire({
                title: "Something went wrong. Please try again later.",
                type: "error"
            });
        }
    });

MVC

public ActionResult ReadMessages(List<long> groupIds)
{
     return new HttpStatusCodeResult(HttpStatusCode.OK);
}

有任何想法吗?

标签: c#jqueryasp.nethttp-post

解决方案


试试这个

var arr= new Array();
arr.push(1);
arr.push(2); 

$.ajax({  
    type: "POST",
    url: urlToPost,
    data: JSON.stringify(arr),
    contentType: "application/json"
   });

推荐阅读