c# - Call Controller Method using Ajax request -
please call method controller using ajax request, below code, error had returned says source of controller cannot found.
here ajax code
function getservices() { var e = document.getelementbyid("catagories"); var struser = e.options[e.selectedindex].value; var id = e.options[e.selectedindex].id; $.ajax({ url: "~/vascontroller/executevas/", //url: '<%= url.action("getservices", "vas") %>', type: 'post', contenttype: 'application/json', data: {"id": id}, success: function (result) { alert(result); } }); }
and here controller method
[webmethod] public static string getservices(string id) { return id; }
kindly advice, still beginner in c# , mvc
in controller file
public class yourcontrollernamecontroller : controller { [httppost] public actionresult dosomething(int? id) { //your code return view(); } }
then in view
$.post('@url.action("dosomething","yourcontrollername")', { id: id }, function (data) { });
Comments
Post a Comment