3
I use ASP.NET MVC 5 and developed a website, when I execute the following Ajax request:
$.ajax({
method: "POST",
url: "/Galeria/AddGaleriaItem",
data: { ID: galeriaID , ObjectString: JSON.stringify(obj) },
dataType: "json"
})
It’s all set up right, but when it runs, Action is NEVER called...
[HttpPost]
public ActionResult AddGaleriaItem(string ID, string ObjectString)
{
ImageIndexer image = JsonConvert.DeserializeObject<ImageIndexer>(ObjectString);
TempData["idImageAdded"] = image.Code;
return Json(new { response = GaleriaCookieController.AddItem(image, ID).Successful });
}
AddGaleriaItem
is inside the Controller Galeria
, but I always get status: 404
and statusText: "Not Found"
: follows print of error:
I also receive a message via HTML like this :
HTTP Error 404.15 - Not Found
The request filtering module is configured to deny a request when the query character string is too long.
EDIT: I tested by decreasing the ObjectString
, but still gives error 404... Only worked if I change POST to GET in both Ajax and Controller.
I believe your objectstring is very long. See if this helps: https://stackoverflow.com/a/42370663/9259549
– Leonardo Buta
@Leonardol decreases the size of the objectstring and keeps giving not found... then I switched the Action from POST to GET and it worked, but I wouldn’t want it to be GET.
– Leonardo Bonetti
I had this mistake once, it seems like it’s the size of the URL. Take a look at this article, it helped me at the time HTTP Error 404.15 - query url Too long
– Diego Lobo
If the Id belongs to the object being serialized then change the method signature in c# to receive the only object already with the type defined, with the Id populated property, also change the way the request is being sent to
data: JSON.stringfy(obj)
– Felippe Tadeu