Passing a variable in Ajax.ActionLink OnSuccess, OnComplete, OnFailure, etc.

I would like to put a div on my main page, which I can update from anywhere on my site using updates. that is, "recorded update", "there was an error", etc.

I am going to style the div differently depending on the type of update. "fail", "success", "info". Basic material so far.

Thus, I have several ActionLinks throughout the site, and they display their contents in the updated targeting, and I can even make them work fine when I pass them the OnComplete, OnBegin, etc. functions. However, I would like to be able to send the parameter of this function to OnBegin.

Example: .OnBegin = "SomeFunction ('failure');"

Any ideas on how to accomplish what I'm doing here?

+3
source share
2 answers
 <% string message = "failed"; %>
        <%=Ajax.ActionLink("TestController","TestAction",
new AjaxOptions{OnBegin="myFunction('" + message + "')"}) %>
+4
source

You can create an anonymous function and then call your function using your paramaks

<%: Ajax.ActionLink("Text", "ActionName", new { id = item.id }, new AjaxOptions { HttpMethod = "Post", OnComplete = "function(){myFunction(" + item.id.ToString() + ");}" })%>

script:

    <script type="text/javascript">
    function onDelete(id) {
        alert("hello "+id);
    }
</script>
+1
source

Source: https://habr.com/ru/post/1710618/


All Articles