Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AjaxOptions OnSuccess callback with parameter not working

I am trying to use AjaxOptions.OnSuccess to call a javascript function and pass a parameter to it. I am able to call a basic function with no parameters without a problem, it's just the parameter passing.

Here is my JS function:

<script type="text/javascript">
    function removeRow (itemId) {

        alert(itemId);
    }
</script>

And my AjaxOptions declaration in razor:

New AjaxOptions With {.OnSuccess = "function(){removeRow(" + item.Id.ToString + ");}"}

On the client side the link appears like this:

<a data-ajax="true" data-ajax-success="function(){removeRow(3);}" href=...

Any idea what I'm doing wrong?

Thanks!

like image 428
Ben Finkel Avatar asked Jul 01 '11 15:07

Ben Finkel


1 Answers

Try this:

New AjaxOptions With {.OnSuccess = String.Format("removeRow({0})", item.Id) }
like image 173
gram Avatar answered Nov 15 '22 04:11

gram