Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

return view after ajax call

after an async call with jquery how can I return a particolar view?

this my caller view:

<script type="text/javascript">

    function Run() {

        $.ajax({
            type: "POST",
            cache: false,
            url: "/Home/Run",
            data: $("#form_run").serializeArray(),
            dataType: "json"
        });

    }

</script>
<form action="javascript:return true;" method="post" id="form_run">
    <input type="text" id="nome" name="nome" />
    <input type="text" id="cognome" name="cognome" />
    <input type="submit" name="submit" value="Run" onclick="Run();" />
</form>

this my controller action:

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Run(string nome, string cognome)
    {
        return View("Result");
    }

can not display view "Result" How?

like image 522
user2336491 Avatar asked Jan 13 '23 11:01

user2336491


1 Answers

You can not return a View from an asynchronous call. An ajax request is meant to avoid doing an entire page cycle.

You should just do a POST back if you want a new View to be returned.

The other option would to be have a callback upon success of the ajax call and set the window.location to the new View so the page does a GET to the new View.

like image 84
Gabe Avatar answered Jan 17 '23 15:01

Gabe