here’s my action.
public virtual JsonResult AddSearch()
{
var data = new { Id = food.Id, Image = food.Image, Name = food.Name};
return Json(data, JsonRequestBehavior.AllowGet);
}
here’s my aJax form
@using (Ajax.BeginForm("AddSearch", "Home", new AjaxOptions { OnSuccess = "AddSearch" }))
my javascript file.
function AddSearch() {
alert("sdfsdfsdf");
}
it works, I see the alert box. my question is how I can get the “Id”, “Name” and “Image” returned by JsonResult. I tried
alert("sdfsdfsdf");
it’s not working.
MVC (to be precise unobtrusiveAjax helpers) will pass the standard jQuery.ajax
success(data, textStatus, jqXHR)callback arguments to theOnSuccessmethod.So you just need to add the parameters to your
AddSearchmethod: