I have such a trouble. I want to return JSON object from Controller to View after AJAX request. JS code is:
$.ajax(
{
url : '/Order/GetArticleForBasicPosition',
data : article,
type : 'POST',
success : function (data)
{
alert("yyyyyyy");
},
error:function (xhr, ajaxOptions, thrownError)
{
alert(xhr.status);
alert(thrownError);
}
});
And Controller is:
[HttpPost]
public JsonResult GetArticleForBasicPosition(string article)
{
Article articleInfo = _service.GetArticleForBasicPosition(article);
return Json(articleInfo);
}
And I get 500 Internal Server Error. I was debugging controller and I see that it gets correct parameter 'article' and service methhod returns correct object. I tryed both GET and POST types of request.
Actually when I modified my controller as:
[HttpPost]
public JsonResult GetArticleForBasicPosition(string article)
{
var articleInfo = new Article() {GoodsName = "ffff", GoodsPrice = 1234, CatalogueName = "uuuuuuui"};
return Json(articleInfo);
}
everything went ok.
I suggest that the reason is my object size(I use EntityFramework and articleInfo has a lot of navigation properties), but didn't found anybody who wrote about the same trouble.
Does anybody know what is the reason of such trouble and if it is size of the object what is the best practice to solve it?
Thanks.