If you have a Ajax.Actionlink and you want to specify a OnBegin with a parameter you need to use the following syntax:

<%=Ajax.ActionLink("text", "Action", "Controller", new { param = someVar }, new AjaxOptions() { OnBegin = string.Format("new Function(‘DoSomeThing(this)’)", index),  HttpMethod = "POST" })%>


Where DoSomeThing is just a function that takes a string as parameter.

Update: added quotes around the real (inner) function, otherwise it’s executed instead of passed on at the creation of the object.

One Response to “ASP.NET MVC AjaxOptions, OnBegin / Onsuccess / OnFailure”
  1. Jeff French says:

    Sweet! Just what I was looking for. Thanks.

  2.  
Leave a Reply


And shepherds we shall be, for thee my Lord for thee, power hath descended forth from thy hand, that our feet may swiftly carry out thy command. We shall flow a river forth to thee, and teeming with souls shall it ever be. In nomine Patris, et Filii, et Spiritus Sancti.