本文介绍了在ASP.NET PageMethods没有工作,如果你有ASP.NET路由实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web方法:

[System.Web.Services.WebMethod]
public static string getCharacterstics(int product_id, int lang_id)
{
    // code goes here...
}

我想用PageMethods喜欢访问它:
(前提是我必须启用ScriptManager的PageMethods条件):

I want to access it using PageMethods like: (Provided the condition that i have Enable PageMethods in ScriptManager):

<script type="text/javascript">
    $(document).ready(
        function () {
            $('#characterstics').html("loading");
            // '<%= product_id_property %>' , '<%= this.LanguageID %>'
            PageMethods.getCharacterstics(0 ,0 , OnSave);
        }
    );

    function OnSave(result) {
    }
</script>

我得到错误的HTTP动词后访问路径..是不允许的

I get the error "the http verb post to access path.. is not allowed"

我GOOGLE了它和搜索也是如此,但基于ASP.NET路由没有得到关于它的任何解决方案。

I googled it and search the SO too but does not get any solution regarding to it Based on ASP.NET Routing.

我所相信的是,由于asp.net的路由服务方法都不能访问。

What i believe is that because of asp.net routing the service methods are not accessible.

另外我想我甚至不能使用,因为asp.net路由太JSON。

In addition i think i cannot even use JSON because of asp.net routing too.

任何帮助是AP preciated。

Any help is appreciated.

更新:

如果我用这个网址运行页面:

If i run the page with this url:

http://localhost:2606/searchdetail.aspx

Web方法成功执行。

The web method executed successfully.

现在

我的路由是这样的:

       routes.MapPageRoute("searchdetail", "searchdetail/{ID}", "~/searchdetail.aspx");
        routes.MapPageRoute("searchdetail", "searchdetail", "~/searchdetail.aspx");

该set_path()将只对2的情况下不即ID,但不工作的情况下1

The set_path() will work only for case 2 i.e without ID but does not work with case 1

如果我尝试

   http://localhost:2606/searchdetail

它正常工作

但如果我尝试使用:

http://localhost:2606/searchdetail/123

这给出了预期的对象错误。

It gives error that object expected.

所以set_path()是选项应该我写什么。

So set_path() is the option what should i write.

推荐答案

目前,的WebMethods不透明地路由框架。有一个变通。你必须直接在你的JavaScript执行以下操作访问PageMethods:

Currently, WebMethods don't work transparently with the Routing framework. There is a work around. You have to access the PageMethods directly by doing the following in your javascript:

PageMethods.set_path('/the/path/to/your/page.aspx');
PageMethods.YourMethod(params, onSuccess, onFailure);

我希望这有助于。

I hope this helps.

这篇关于在ASP.NET PageMethods没有工作,如果你有ASP.NET路由实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 20:45