Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I pass parameters to the OnSuccess function of the AjaxOptions class in ASP.NET MVC?

How can I pass parameters to the OnSuccess function of the AjaxOptions class in ASP.NET MVC?

Here's my code but it doesn't work:

<%= Ajax.ActionLink("Delete", 
                    "Delete", 
                    "MyController", 
                    New With {.id = record.ID}, 
                    New AjaxOptions With 
                    {
                        .Confirm = "Delete record?", 
                        .HttpMethod = "Delete", 
                        .OnSuccess = "updateCount('parameter')"
                    })
%>

UPDATE

Setting the OnSuccess property to (function(){updateCount('parameter');}) solved my problem:

<%= Ajax.ActionLink("Delete", 
                    "Delete", 
                    "MyController", 
                    New With {.id = record.ID}, 
                    New AjaxOptions With 
                    {
                        .Confirm = "Delete record?", 
                        .HttpMethod = "Delete", 
                        .OnSuccess = "(function(){updateCount('parameter');})"
                    })
%>
like image 960
Bryan Roth Avatar asked Apr 09 '10 14:04

Bryan Roth


1 Answers

You should be able to use a jQuery selector to populate a value from a field in the page:

<%= Ajax.ActionLink("Delete", 
                    "Delete", 
                    "MyController", 
                    New With {.id = record.ID}, 
                    New AjaxOptions With 
                    {
                        .Confirm = "Delete record?", 
                        .HttpMethod = "Delete", 
                        .OnSuccess = "updateCount($('#SomeField).val()))"
                    })
%>

Also take a look here: Can I pass a parameter with the OnSuccess event in a Ajax.ActionLink

like image 114
Dave Swersky Avatar answered Oct 25 '22 18:10

Dave Swersky