PageMethods with ASP.Net MVC

前端 未结 2 1856
情话喂你
情话喂你 2021-01-18 18:45

I have found ASP.Net PageMethods very handy and easy to use, but I have just started developing using MVC and am not sure how to use them?

What is the equivalent of

2条回答
  •  时光说笑
    2021-01-18 19:38

    I don't think you need page methods. Page methods in asp.net are a way to expose methods in the page class to your client-side code.

    In MVC, you don't have a page class, so you can just issue an XHR to a url (../controller/action/params, or whatever), and return JSON from the action.

    Update: After re-reading your question, it sounds like you want to know how to issue an XHR from the client. In raw javascript, you can just use the XMLHttpRequest object, but whatever JS library you are using probably has a nicer wrapper. jQuery's, for instance, is here

提交回复
热议问题