Tuesday, July 13, 2010

Passing parameter with the OnSuccess or OnComplete event in Ajax.BeginForm

passing a parameter with the OnSuccess event in a Ajax.ActionLink or Ajax.BeginForm is bit tricky...

< script type="text/javascript">
function ExeOnComplete(strParam1)
{
 alert('strParam1');
}
< /script>"


using (Ajax.BeginForm("Create", "Profile", new AjaxOptions { HttpMethod = "Post", OnComplete = "function(){ExeOnComplete('abc');}"}))
{
// your code here
}

2 comments:

  1. this approach doesn't work for me. it generates a runtime error "Expected identifier" in the unobtrusive ajax library

    ReplyDelete
  2. This doesn't work with unobtrusive javascript. Have you figured out how to do this with unobtrusive javascript? Any help would be appreciated.

    Thanks

    ReplyDelete

5 Strategies for Getting More Work Done in Less Time

Summary.    You’ve got more to do than could possibly get done with your current work style. You’ve prioritized. You’ve planned. You’ve dele...