2

オートコンプリート機能を実現するために ASP.NET ハンドラーを呼び出す Web パーツがあります。

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);
                }
            });
        });

"My Service" は、webpart プロジェクト内の SharePoint レイアウト フォルダーです。

JQuery を使用して呼び出しを行うと、「型 'MyService.MyAutoComplete' を作成できませんでした」というエラーがスローされます。

どんな助けでも感謝します。

4

2 に答える 2

1

IHttpHandlerを実装するときは、次の実装を提供する必要があります。

  • ProcessRequest()メソッド (あなたが行う) 、
  • IsReusableプロパティ (これはありません)。

したがって、クラスは のすべての抽象メンバーの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 に答える