Monday, April 4, 2016

Set url parameter of $.getJSON() method using @Url.Action() in ASP.NET MVC

Here's how you set the first parameter of $.getJSON() which is url using @Url.Action() where GetProductDetails is the action name and Product is the controller name. Make sure to surround it with single quotes.

Javascript Code:
1
2
3
4
5
function GetProductData(event) {
    $.getJSON('@Url.Action("GetProductDetails","Product")', function (prod) {
        alert(prod);
    });
}

0 comments:

Post a Comment