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

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>


Last updated:12/7/2017 12:00:18 AM

1 Answers

Manish Kumar
Manish Kumar

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