PageMethods没有在ASPX页面中定义 [英] PageMethods is not Defined in ASPX Page

查看:494
本文介绍了PageMethods没有在ASPX页面中定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看,我只能在同一时间假设工作过的一些旧的code。

I'm looking at some old code that I can only assume worked at one time.

MyPage.aspx:

function GetCompanyList(officeId) {
    var companyList = document.getElementById('<%= CompanyDropDown.ClientID %>');
    if (companyList.length == 0)
        PageMethods.GetCompanyList(officeId, OnGetCompanyList);
    else
        EditCompany();
}

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" />

后面的 code:

[System.Web.Services.WebMethod()]
[System.Web.Script.Services.ScriptMethod()]
public IEnumerable<CompanyMinimum> GetCompanyList(int officeId) {
    return (
        from c in Repository.Query<Company>()
        where !c.IsDeleted && c.TypeEnumIndex == (short)CompanyRelationshipType.Hotel
        select new CompanyMinimum() {
            id = c.Id,
            desc = c.Description
        }
    ).ToList();
}

但在调用 PageMethods.GetCompanyList()在第一个片段,铬报道:

But at the call to PageMethods.GetCompanyList() in the first snippet, Chrome reports:

PageMethods没有定义

PageMethods is not defined

有人能看到发生了什么变化,以prevent这从工作?

Can anyone see what has changed to prevent this from working?

注:我发现类似的问题,但他们似乎都与此相关的code不工作的母版页或用户控件,这不是这里的情况

推荐答案

<一个href="http://msdn.microsoft.com/en-us/library/system.web.ui.scriptmanager.enablepagemethods.aspx"><$c$c>EnablePageMethods实际上只有一个子类的方法进行交互是公开静态,并归结为一个的WebMethod

EnablePageMethods actually only interacts with methods of a Page subclass that are public, static, and attributed as a WebMethod.

GetCompanyList 有2那些,只是也需要静态

GetCompanyList has 2 of those and just also needs to be static.

[System.Web.Services.WebMethod()]
[System.Web.Script.Services.ScriptMethod()]
public static IEnumerable<CompanyMinimum> GetCompanyList(int officeId) {
    // ...
}

和,我怀疑这是怎么回事的是,它的离开 PageMethods 不确定的客户端,如果它没有找到有所有3的任何方法。

And, I suspect what's happening is that it's leaving PageMethods undefined client-side if it doesn't find any methods that have all 3.

这篇关于PageMethods没有在ASPX页面中定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆