jothi kumar

jothi kumar

  • 1.6k
  • 107
  • 56.3k

how to search in mvc5

Aug 22 2014 1:52 AM
hi to all,
                Here i done searching for autocomplete textbox .
 
 Let us consider now i have total pages 10, now i filter respective record in table then i will filter as per given information and that have 5 pages . if i click 2 nd from filtering record pages then total page should be refreshing  again i got 10 pages 
 
Here i used this code:
In controller:
public JsonResult SearchAutoCompleter(string term ,string Branchlist,int? page)
{
var myObjects = (from o in db.Branches
join cou in db.Country on o.Country_Id equals cou.Country_Id
where o.Branch_Name.Contains(term)||cou.Country_Name.Contains(term)
select new
{
label = o.Branch_Name,o.Country_Id
}).Distinct().Take(3);
ViewBag.term = myObjects;
return Json(myObjects, JsonRequestBehavior.AllowGet);
}
 
In index using Ajax function:-
 
<script type="text/javascript" src="~/Scripts/jquery-ui-1.10.4.min.js"></script>
<script type="text/javascript" src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#autocomplete").autocomplete({
source: "@Url.Action("SearchAutoCompleter","Branch")",
messages: {
noResults: 'no result found',
results: function () { }
}
});
});
</script>
 
Design:-
@Html.TextBox("SearchName", ViewBag.branch_Name as string, new { @id = "autocomplete" }) 
 
if u not understand kindly let me know.  Here i want to set paging for filtered record

Answers (1)