Making a Simple Ajax call to controller in asp.net mvc on button click

Total Post:13

Points:91
 485  View(s)
Ratings:
Rate this:

I am unable to send ajax request to controller action. I think i am missing something ..

<script type="text/javascript">

    $('#UseShipAddr').click(function () {
        $.ajax({
            url: "@(Url.Action("article", "Home"))",
            type: "POST",
            data: { id: 50 },
            cache: false,
            async: true,
            success: function (data) {
                alert(data);
            }
        });
    });
</script>


  1. Post:52

    Points:366
    Re: Making a Simple Ajax call to controller in asp.net mvc on button click

    try this code..

    <script>
        $(document).ready(function () {
            $("#tarticle").on("click", function () {
                $.ajax({
                    url: '@Url.Action("article", "Home", new { @type = "articles" })',
                    type: "GET",
                    success: function (data) {
                        alert(data);
                    }
                })
            });
    </script>

    hope this helps you..

Answer