2

我有一个 webpart 调用 ASP.NET 处理程序来完成自动完成功能。

ASHX File
    <%@ WebHandler Language="C#" Class="MyService.MyAutoComplete" CodeBehind="MyAutoComplete.ashx.cs" %>

代码隐藏文件

namespace MyService
{
    /// <summary>
    /// Summary description for MyAutoComplete
    /// </summary>
    public class MyAutoComplete : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            var searchTerm = context.Request.QueryString["term"].ToString();

            context.Response.Clear();
            context.Response.ContentType = "application/json";


            var search = GetList();

            JavaScriptSerializer jsSerializer = new JavaScriptSerializer();
            string json = jsSerializer.Serialize(search);
            context.Response.Write(json);
            context.Response.End();
        }

    }
}

这是我的 JQuery 调用

$(function () {
            $("#<%= txtSearchInput.ClientID %>").autocomplete({
                source: "/_Layouts/My Service/MyAutoComplete.ashx",
                minLength: 2,
                select: function (event, ui) {
                    $(this).val(ui.item.value);
                }
            });
        });

“我的服务”是 webpart 项目中的 SharePoint 布局文件夹。

当我通过 JQuery 进行调用时,它会引发以下错误“无法创建类型'MyService.MyAutoComplete'”

任何帮助表示赞赏。

4

2 回答 2

1

实现IHttpHandler时,您必须提供以下实现:

因此,MyAutoComplete无法实例化该类,因为它没有为所有IHttpHandler的抽象成员提供实现。

由于您的处理程序显然是无状态的,您可以IsReusable按如下方式实现:

public bool IsReusable
{
   get {
       // Handler is stateless, we can reuse the same instance
       // for multiple requests.
       return true;
   }
}
于 2012-04-30T05:08:37.753 回答
0

似乎 SharePoint 组件有自己的识别组件的方式:)。谷歌搜索后,我找到了以下解决方案。

<%@ WebHandler Language="C#"  Class="MyService.MyAutoComplete,MyProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=87c41094797c589e" %>
于 2012-05-01T14:50:49.560 回答