Using ASP.NET PageMethods with JQuery DataTables?

老子叫甜甜 提交于 2019-12-14 03:05:40

问题


For starters, I'm new to ASP.NET Ajax stuff, and only getting back into JQuery after a long hiatus, so excuse any stupid sounding parts of this question :)

I would like to use the DataTable plug-in for JQuery in my ASP.NET page. Additionally, I'd like to do server-side pagination. It seems like in order to do that, I would have to create a web service and provide the url of said service to the "sAjaxSource" property of the DataTable.

I'm just now discovering "PageMethods", which appear to be similar to a web service but are written directly on a specific page. It would be nice if the DataTable plug-in and the ASP.NET "PageMethods" would work nicely together, but I'm not sure how that would work.

So I guess I'm wondering if the url used for sAjaxSource can be stated in a way that points to the page itself and means "use this PageMethod on this page". Or is there a built in way to manually construct the ajax call/response so I could use something like "PageMethods.GetTable()" directly? Hopefully this makes sense, but please let me know if it is unclear. Thanks in advance!


回答1:


You can call a Page Method on a page in the same way you would a web service, like this

MyPage.aspx/WebMethodName

Just make sure your method is static and has the [ScriptMethod] attribute added.



来源:https://stackoverflow.com/questions/6686019/using-asp-net-pagemethods-with-jquery-datatables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!