参考
docs.microsoft.com
$("#jsexe4").on('click', function () {
var foo = {};
foo.Title = "botw";
foo.Count = 1000;
foo.Contents = []
foo.Contents.push("c-1")
foo.Contents.push("c-2")
var postData = JSON.stringify(foo);
$.ajax(
{
url: "/Json/TestJsonFunc4",
type: 'POST',
data: postData,
dataType: 'json',
contentType: 'application/json',
error: function () { },
complete: function (data) {
console.log(data.responseJSON);
},
}
);
});
public class JsonViewModel2
{
public string Title { get; set; }
public int Count { get; set; }
public List<string> Contents{get;set;}
}
[HttpPost]
public ActionResult TestJsonFunc4(MvcLearn.Models.JsonViewModel2 model)
{
Debug.WriteLine("Title:" + model.Title);
Debug.WriteLine("Count:" + model.Count);
foreach (var item in model.Contents)
{
Debug.WriteLine("Contents:" + item);
}
var TestData = new
{
div = "営業部",
address = "東京都千代田区一ツ橋",
};
return new JsonResult() { Data = TestData, ContentEncoding = System.Text.Encoding.UTF8, ContentType = @"application/json" };
}