Moo*_*ons 4 c# asp.net json scriptmanager url-routing
我有一个网络方法:
[System.Web.Services.WebMethod]
public static string getCharacterstics(int product_id, int lang_id)
{
// code goes here...
}
Run Code Online (Sandbox Code Playgroud)
我想使用PageMethods来访问它:(假设我在ScriptManager中启用PageMethods的条件):
<script type="text/javascript">
$(document).ready(
function () {
$('#characterstics').html("loading");
// '<%= product_id_property %>' , '<%= this.LanguageID %>'
PageMethods.getCharacterstics(0 ,0 , OnSave);
}
);
function OnSave(result) {
}
</script>
Run Code Online (Sandbox Code Playgroud)
我收到错误"http动词帖子访问路径..不允许"
我搜索了它并搜索了SO,但没有得到任何有关它的解决方案基于ASP.NET路由.
我认为,由于asp.net路由,服务方法无法访问.
另外我认为我甚至不能使用JSON,因为asp.net路由也是如此.
任何帮助表示赞赏.
更新:
如果我用这个网址运行页面:
http://localhost:2606/searchdetail.aspx
Run Code Online (Sandbox Code Playgroud)
Web方法已成功执行.
现在
我有这样的路由:
routes.MapPageRoute("searchdetail", "searchdetail/{ID}", "~/searchdetail.aspx");
routes.MapPageRoute("searchdetail", "searchdetail", "~/searchdetail.aspx");
Run Code Online (Sandbox Code Playgroud)
set_path()仅适用于案例2,即没有ID,但不适用于案例1
如果我试试
http://localhost:2606/searchdetail
Run Code Online (Sandbox Code Playgroud)
它工作正常
但如果我尝试使用:
http://localhost:2606/searchdetail/123
Run Code Online (Sandbox Code Playgroud)
它给出了对象所期望的错误.
所以set_path()是我应该写的选项.
Neh*_*eha 11
目前,WebMethods不能与Routing框架透明地工作.有一个工作.您必须通过在javascript中执行以下操作直接访问PageMethods:
PageMethods.set_path('/the/path/to/your/page.aspx');
PageMethods.YourMethod(params, onSuccess, onFailure);
Run Code Online (Sandbox Code Playgroud)
我希望这有帮助.
归档时间: |
|
查看次数: |
4942 次 |
最近记录: |