ASP.Net MVC Ajax call that returns JsonResult

I am starting to learn ASP.Net MVC (candidate for release) and I have small problems. I might just be picky, but I thought I'd ask.

I want to use the built-in (advanced) ASP.NET Ajax methods to call my controller called "GetNames", which returns a JsonResult object. I saw examples that use the $ .getJSON () jQuery method, but I would rather do something like this:

 <%using ( Ajax.BeginForm("GetNames", new AjaxOptions() { OnSuccess = "GetNamesSuccess", OnBegin = "GetNamesBegin", OnComplete = "GetNamesComplte", OnFailure = "GetNamesFailure" } ) ) { %>

    <%=Html.TextBox("DummyData") %>
    <input type=submit />

<% } %>

<script type="text/javascript">
    function GetNamesSuccess()
    {
        alert("Success");
    }

    function GetNamesBegin()
    {
        alert("Begin");
    }

    function GetNamesComplete()
    {
        alert("Complete");   
    }

    function GetNamesFailure()
    {
        alert("Failure");
    }        
</script>

"", , , Json, , , , . ... , Ajax.BeginForm , Json OnSuccess, OnComplete.

?

+3
1

MicrosoftAjax.js MicrosoftMvcAjax.js javascript ? , Ajax. , MicrosoftAjax.js, Ajax - javascript , , .

, Ajax ViewResult ( Redirect) Json, . - javascript , , postback, Json.

+4

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


All Articles