我如何...通过ajax调用在视图中传递json [英] How do i...get json in controller passed by view through ajax call
问题描述
大家好,
我将json值从视图传递到控制器,无法在控制器中解析请指导。
下面用于传递Json的代码,无法在Create方法中使用Create方法
Hi All,
I am passing json value from view to controller not able to parse in the controller please guide .
Below code for passing Json, not able to get in Curriculum Controller in Create method
<script>
$(document).ready(function () {
$("#target").click(function (data, status) {
var arr = { City: 'Moscow', Age: 25 };
$.ajax({
url: 'http://localhost:61255/Curriculum/Create',
type: 'POST',
data: JSON.stringify(arr),
contentType: 'application/json; charset=utf-8',
dataType: 'json',
async: false,
success: function (msg) {
alert(msg);
}
});
});
});
</script>
我的尝试:
下面的代码解析json但不工作
[HttpPost]
public ActionResult Create(IDictionary< string,> model)
{
}
What I have tried:
Below code to parse the json but not working
[HttpPost]
public ActionResult Create(IDictionary<string,> model)
{
}
推荐答案
( document )。ready( function (){
(document).ready(function () {
( #target)。click( function (data,status){
< span class =code-keyword> var arr = {City:' Moscow' ,年龄: 25 };
("#target").click(function (data, status) { var arr = { City: 'Moscow', Age: 25 };
.ajax({
url:' http:// localhost:61255 / Curriculum / Create',
类型: ' POST',
data: JSON .stringify(arr ),
contentType:' application / json; charset = utf-8',
dataType:' json',
async: false ,
成功: function (msg){
警报(MSG);
}
});
});
});
< / script>
.ajax({ url: 'http://localhost:61255/Curriculum/Create', type: 'POST', data: JSON.stringify(arr), contentType: 'application/json; charset=utf-8', dataType: 'json', async: false, success: function (msg) { alert(msg); } }); }); }); </script>
我的尝试:
下面的代码解析json但不工作
[HttpPost]
public ActionResult Create(IDictionary< string,> model)
{
}
What I have tried:
Below code to parse the json but not working
[HttpPost]
public ActionResult Create(IDictionary<string,> model)
{
}
这篇关于我如何...通过ajax调用在视图中传递json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!