I have a controle like this
public JsonResult GetSizes(long Id)
{
try
{
//get some data and filter y Id
}
catch (Exception ex) { }
return Json(//data);
}
I need to get that by following json by ajax request
var sizes = [];
$.ajax({
type: 'POST',
async: false,
data: { 'Id': selectedId },
url: "/<Controler name>/GetSizes",
dataType: 'json',
contentType: 'application/json; charset=utf-8',
error: function (xhr) {
alert('Error: ' + xhr.statusText);
return false;
},
success: function (result) {
if (result.Result != null) {
if (result.Result.length > 0) {
sizes = result;
}
}
}
});
But this give me an Server error. How can i fix this.
Server error? Can you post that? andGetSizesdoesn't help to figure out problemurl: "/<Controler name>/GetSizes",has the correct controller name in it and not this<Controler name>placeholder. Otherwise, there's your error source. On a different note, generate the url using"@Url.Action("controller_name", "action_name")"by filling in the correct controller and action names.return Json("data", JsonRequestBehavior.AllowGet);addJsonRequestBehavior.AllowGetin json return.