Удалите заголовок запроса application/json
, поскольку вы не отправляете запрос в кодировке JSON:
Ext.Ajax.request({
url: '/Blog/SavePost',
method: 'POST',
params: {
id: currentPost.data.Id,
title: currentPost.data.Title,
text: currentPost.data.Text,
authorName: currentPost.data.AuthorName,
authorEmail: currentPost.data.AuthorEmail,
postDate: currentPost.data.PostDate
},
failure: function (response) { },
success: function (response, opts) { }
});
Лично я бы порекомендовал, чтобы действие вашего контроллера напрямую принимало модель Post
вместо того, чтобы каждое свойство использовалось в качестве аргумента, а затем вручную копировало их в объект Post:
[HttpPost]
public ActionResult SavePost(Post post)
{
var postRepository = new PostRepository();
postRepository.Add(post);
return Json(...);
}
Подшивка модели по умолчанию позаботится обо всем. Теперь, если вы хотите использовать JSON в качестве запроса, вы можете использовать метод JSON.stringify
, встроенный в современные веб-браузеры:
Ext.Ajax.request({
url: '/Blog/SavePost',
method: 'POST',
headers: {
'Content-Type': 'application/json;charset=utf-8'
},
params: {
post: JSON.stringify({
id: currentPost.data.Id,
title: currentPost.data.Title,
text: currentPost.data.Text,
authorName: currentPost.data.AuthorName,
authorEmail: currentPost.data.AuthorEmail,
postDate: currentPost.data.PostDate
})
},
failure: function (response) { },
success: function (response, opts) { }
});