Asp.net的mvc阿贾克斯JSON(post数组) [英] Asp.net Mvc Ajax Json (post Array)
本文介绍了Asp.net的mvc阿贾克斯JSON(post数组)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
JavaScript的\ jQuery的:
javascript\jQuery:
var items = new Array();
var obj { Begin: "444", End: "end" };
items.push(obj);
items.push(obj);
var request = {
DateStart: $("#DateStart").val(),
mass: items
};
$.post("/Home/Index", request, null,
"json");
C#的mvc指数控制器
C# Mvc Index Controller
public class MyClass
{
public string Begin;
public string End;
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(
string DateStart,
MyClass []mass)
{
System.Diagnostics.Debug.WriteLine(mass[0].Begin);
}
如何执行此code?谢谢。
how to execute this code? thanks.
推荐答案
U可以不通过质量:项目
,并期望它能够自动序列化为一个JSON数组,你要么需要迭代和构建JSON(坏的计划),或使用 JSON库(好的计划)
U can't pass mass: items
and expect it to be serialized as a JSON array automatically, you will need to either iterate and construct the JSON (bad plan) or use a JSON library(good plan)
这篇关于Asp.net的mvc阿贾克斯JSON(post数组)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文