jQuery自动完成功能正常,但结果不可见

时间:2015-11-04 19:41:34

标签: jquery jquery-ui model-view-controller autocomplete

Autocomplete

我使用MVC和jQuery UI在此文本框中获取自动完成功能,无论出于何种原因,它都无法正确显示结果。我已通过ActionResult和浏览器验证结果返回但未正确显示。我已经知道jQuery和jQueryUI的工作原理,因为我有一个可用的日期选择器。

public ActionResult ProfessorFirstAutoComplete(string term)
    {
        var firstNameQuery = db.Professors.Where(pr => pr.FirstName.StartsWith(term));
        SelectList firstNames = new SelectList(firstNameQuery, "Id", "FirstName");

        return Json(firstNames, JsonRequestBehavior.AllowGet);
    }

<script>
    $(function () {
        $("#datepicker").datepicker();
    });

    $(document).ready(function () {
        $("#profFirstBox").autocomplete(
            {
                source: '@Url.Action("ProfessorFirstAutoComplete", "Events")'
            });
    })
</script>

<div class="form-group">
        @Html.LabelFor(model => model.Professor.FirstName, "First Name", htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.TextBoxFor(model => model.Professor.FirstName, htmlAttributes: new { @class = "form-control", @id = "profFirstBox" })
            @Html.ValidationMessageFor(model => model.Professor, "", new { @class = "text-danger" })
        </div>
    </div>

0 个答案:

没有答案