Passing parameter to onSuccess callback function
ajax, asp.net-mvc, forms
Solution
Since this parameter is passed to the controller action you could have this controller action return it as part of the JSON response:
public ActionResult DoComment(int id, int parentId)
{
...
return Json(new
{
Message = "foo",
ParentId = parentId
}, JsonRequestBehavior.AllowGet);
}
so that you could use it in your success callback:
function publishCommentSuccess (json) {
alert(json.ParentId);
...
};
Problem
I have the following form: ``` @using (Ajax.BeginForm("DoComment", "Publication", new { id = Model.Publication.OID, parentId = Model.OID }, new AjaxOptions { OnSuccess = "publishCommentSuccess" })) { //some code } ``` How can I pass `parentId` into `publishCommentSuccess` function? ``` function publishCommentSuccess (json) { if (!json.Result) showAuthBox(); else alert(json.Message); }; ``` Thanks.