我如何发送int数组从阿贾克斯到C#MVC?数组、int、MVC、阿贾克斯到

2023-09-11 01:01:41 作者:过去的过不去

我如何发送int数组从$就到C#MVC?

解决方案

  $。阿贾克斯({
          网址:< URL的作用&gt ;,的
          键入:POST,
          数据:JSON.stringify([1,2,3]),
          数据类型:JSON,
          的contentType:应用/ JSON的;字符集= UTF-8
});
 

和在动作

 公众的ActionResult ReceiveIntArray(INT []整数)
{
   ...
}
 

MVC会自动解析JSON。

检查出this问题。

引用数据类型 数组 Java基础知识 4

How can I send int array from $.ajax to c# mvc?

解决方案

$.ajax({
          url: <Url of the action>,
          type: "POST",
          data: JSON.stringify([1,2,3]),
          dataType: "json",
          contentType: 'application/json; charset=utf-8'
});

and in the action.

public ActionResult ReceiveIntArray(int[] ints)
{
   ...
}

mvc should parse the json automatically.

check out this question.