C# 如何在asp.net mvc控制器中获取post json数据
你能帮助我如何在控制器中获取json数据吗C# 如何在asp.net mvc控制器中获取post json数据,c#,asp.net-mvc,json,jquery,C#,Asp.net Mvc,Json,Jquery,你能帮助我如何在控制器中获取json数据吗 $.ajax({ type: 'Post', url: 'getdata', dataType: 'json', data: JSON.stringify(value), //value is an array contentType: 'application/json', success: function (data) { }, error:
$.ajax({
type: 'Post',
url: 'getdata',
dataType: 'json',
data: JSON.stringify(value), //value is an array
contentType: 'application/json',
success: function (data) {
},
error: function (xhr, textStatus, errorThrown) {
}
});
控制器:
public ActionResult getdata()
{
view()
}
我对控制器或模型没有任何想法。建议一些想法
您需要有一个与json模型相匹配的参数,其类型如下:
您的模型可能看起来像:
public class MyModel{
public string FirstName {get; set;}
public string LastName{get; set;)
public bool IsHappy {get; set;}
// etc. etc
}
public ActionResult GetData(MyModel data)
{
// do what you need with the data here
return View();
}
这个问题太棒了,我想你最好用谷歌搜索一下“json模型asp.NETMVC”,然后从那里开始。稍后我将添加一些链接
[编辑]-如承诺的那样,有几个链接:
上面列表中的最后一个链接几乎完美地描述了你需要做什么。我建议你好好学习。祝你好运。我已经在谷歌上搜索过了,还没有弄清楚。你能帮我在模型中声明吗。。。但这将取决于您的模型属性。显示generis类型摘要的粗略尝试