How to call my view Asp.Net MVC with ajax

Asked

Viewed 158 times

0

I am starting my studies with Asp.Net MVC and I am able to call a view from the main menu. I have an initial view "_Layout" with the following menu item:

<li>
  <input type="radio" name="tabs" class="rd_tabs" id="tab3">
  <label for="tab3">Currículo</label>
</li>

And I’m trying to call the controller/action this way:

@section Scripts{
    <script>
            $(document).ready(function () {
                $('#tab3').click(function () {
                    $.ajax
                        ({
                            url: "/Home/Curriculo",
                            type: 'GET',
                            success: function (dados) {
                                console.log("sucesso");
                            },
                            error: function (erro) {
                                console.log("falha");
                            }
                        });
                });
            })
    </script>
}

But nothing happens, even though Function is running and printing "success" on the console. I’ve tried calling the url in different ways but nothing has worked.

I would like the help of colleagues to know where I am going wrong. Thank you!

  • Well try instead of successfully having the console print the data and look if there is an html code, what happens and that it returns on the same page the data you would have to do something with the page returned.

  • Yes, it returns the page, but I did not know that I would have to treat the return. I imagined that the action itself would call the page.

1 answer

0

Well try instead of successfully having the console print the data and look if there is an html code, what happens and that it returns on the same page the data you would have to do something with the page returned.

I guess you don’t need the ajax do like this.

    $(document).ready(function () {
        $('#tab3').click(function () {
              window.location = "/Home/Curriculo"  

        });
    })
  • Eureca, worked with your tip Rodrigo! Value friend , thanks for the help!

  • Cool, don’t forget to vote.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.