我正在阅读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