オートコンプリート機能を実現するために 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' を作成できませんでした」というエラーがスローされます。
どんな助けでも感謝します。