ajax - PagedList MVC With JQuery UI Autocomplete Causing Error -
i'm trying use jquery ui autocomplete on text box filter through paged list , dynamically update list shows starts value filter. whenever start typing search box following error:
syntax error: unexpected token <
here's controller:
[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); }
here's view:
@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> }
is i'm trying here possible? going wrong way? if need more information let me know.
the ajax function returning html error trying getting parsed function. fail , error out because first character '<'
Comments
Post a Comment