我正在閱讀MVC 2 in Action一書。有關自動完成的章節已作爲參考結束。 在控制器中,返回的Json結果不會轉換爲自動完成列表。這本書沒有使用Json,但我不能使用他們的替代品與一個通用的列表。MVC:無法自動完成工作
所以我的觀點是;
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<SHP.WebUI.Models.HolidayRequestViewModel>" %>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$("input#SearchText").autocomplete('<%: Url.Action("FindNames", "Employee") %>');
});
</script>
<p>You must make sure that the correct person to approve your Annual Leave is currently selected</p>
<p>Your current approver is <%: Html.DisplayFor(model => model.ApproverName) %></p>
<p>If you want to change your approver, enter his/her name here and make your selection.</p>
<p><%: Html.TextBoxFor(model => model.SearchText) %></p>
<div id="test-panel" class="ui-state-default"> This panel will disappear on command.</div>
而我的控制器是;
public JsonResult FindNames(string q)
{
List<EmployeeName> filteredEmployees =
Employee.GetAllCurrentEmployeesNames().Where(x => x.Fullname.ToLower().Contains(q.ToLower())).ToList();
return Json(filteredEmployees, JsonRequestBehavior.AllowGet);
}
* EDITED * 與發送參數的問題已得到修復,通過使用 「串Q」。明顯的呃?現在是將JSON返回到自動完成列表中的一種情況。
我不知道ASP.NET自動完成機制,但我期望問題是URL上參數的名稱。自動完成生成的URL是什麼 - 命名參數是什麼?你有沒有爲這個行動設置特定的路線? – Rup 2010-11-18 14:30:16