Use
jQuery's load
method[
^]:
$(function(){
$("#search").keyup(function(){
var data = { searchString: $(this).val() };
$("#catList > tbody").load("/Admin/ViewCategory #catList > tbody", data);
});
});
I'd also be inclined to return a
PartialView
from the action in response to an AJAX request:
public ActionResult ViewCategory( string searchString )
{
var categories = from m in dbnew.tbl_category
select m;
if (!string.IsNullOrEmpty(searchString))
{
categories = categories.Where(s => s.cat_name.Contains(searchString));
}
if (Request.IsAjaxRequest()) return PartialView(categories);
return View(categories);
}
That way, the response to the AJAX request doesn't include the HTML from the layout page, which it would ignore anyway.