Skip to content Skip to sidebar Skip to footer

Call C# Method With Js

I am trying to create a login page that changes dynamically based on user attributes, specifically a username and role that is logged into a cookie. The login works fine; however,

Solution 1:

Create your method as a web-service (web-api is good) then call it using jS ajax, here's an example i use with web-api and JS (this is posting data, use get if you have nothing to post)

$.ajax({
    type: 'Post',
    contentType: "application/json; charset=utf-8",
    url: "//localhost:38093/api/Acc/",  //method Name 
    data: JSON.stringify({ someVar: 'someValue', someOtherVar: 'someOtherValue'}),
    dataType: 'json',
    success: someFunction(), // callback above
    error: function (msg) {
        alert(msg.responsetext);
    }
});

Post a Comment for "Call C# Method With Js"