Dear team , i am trying to pass a array of values from ajax to controller but i always returing success or 200 despite hitting the controller.
Even with checkpoints it is not hitting
this is my ajax code
i have modidied the url to empty because i dont have enough reputation to post urls
and this is my conroller
public JsonResult AssignToHR(List ids)
{
foreach (var id in ids)
{
// Do something with the ID
}
return Json(new { success = true });
}
i am not sure where i am wrong . please guide.
Naimish MakwanaPosted Apr 10, 2023, 7:17 AM
t seems that the URL in your AJAX code is empty, which means the AJAX request is not being sent to the correct URL. You need to specify the correct URL for the AJAX request to hit the controller action.
Additionally, you might want to check if your controller action is decorated with the
[HttpPost]attribute to ensure that the action is only executed when a POST request is received.Thanks
Jignesh KumarPosted Apr 10, 2023, 6:41 AM
Hello,
You need to check url only, Code looks proper just check with url and method parameters both should match then mesthod will hit,
For more you can refer this link whic will help you out,
https://www.c-sharpcorner.com/blogs/post-the-data-to-asp-net-mvc-controller-using-jquery-ajax