首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PagedList MVC与JQuery UI自动完成导致错误

问PagedList MVC与JQuery UI自动完成导致错误
EN

Stack Overflow用户
提问于 2015-05-11 17:03:22
回答 1查看 631关注 0票数 1

我试图使用文本框上的JQuery UI自动完成来筛选分页列表并动态更新列表,因此它只显示以筛选器的值开头的任何内容。然而,每当我开始在搜索框中输入时,我就会得到以下错误:

语法错误:意外令牌<

这是我的控制器:

代码语言:javascript
复制
    [HttpGet]
    public ActionResult Index(string filter, int currentPage = 1)
    {
        List<string> allEmails = null;

        if (!string.IsNullOrEmpty(filter))
        {
            allEmails = dataContext.Emails
                .Where(x => x.email.StartsWith(filter))
                .Select(x => x.email)
                .ToList();
        }
        else
        {
            allEmails = dataContext.Emails
                .Select(x => x.email)
                .ToList();

        }
        PagedList<string> model = new PagedList<string>(allEmails, page, pageSize);
        ViewBag.Emails = allEmails.OrderBy(x => x).Skip((page - 1) * pageSize).Take(pageSize);
        ViewBag.Filter = filter;
        return View(model);
    }

以下是我的看法:

代码语言:javascript
复制
 @model PagedList<string>
 @using PagedList
 @using PagedList.Mvc

<div id="paginatedDiv">
    <table id="pageinatedTable">
         <tr>
             <th>
                 Email
             </th>
         </tr>
         @foreach (var item in ViewBag.Emails)
         {
              <tr>
                 <td>
                     @item
                 </td>
             </tr>
         }
     </table>

     @Html.PagedListPager(Model,
        (page) => Url.Action("Index", "Home", new
        {
            page,
            pageSize = Model.PageSize,
            filter = ViewBag.Filter
        }),
        PagedListRenderOptions.ClassicPlusFirstAndLast)
 </div>
 @Html.TextBox("search")


 @section scripts
 {
     <script type="text/javascript">
         $(document).ready(function () {
              $('#search').autocomplete({
                     source: function(request, response)
                     {
                        $.ajax({
                            url: '@Url.Action("Index", "Home")',
                            dataType: "json",
                            contentType: 'application/json, charset=utf-8',
                            data: {
                                filter : $("#search").val(),
                                page : '@Model.PageNumber'
                            },

                            error: function (xhr, status, error) {
                                alert(error);
                            }

                        })},
                      minlength: 1
             });

         });
     </script>
  }

我在这里做的事有可能吗?我是不是走错路了?如果你需要更多的信息,请告诉我。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-12 03:12:26

Ajax函数返回一个HTML错误,该错误试图被解析到该函数。它将失败并出错,因为第一个字符将是'<‘类似

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30173538

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档