I try to search content based on ajax. i successfully build search function on button click.
Now i want to show search result when typing in search textbox.
My Action Method under ProjectManager Controller
public ActionResult SearchAjax(string SearchKey )
{
ProjectUtility OProjectUtility = new ProjectUtility();
IEnumerable<Project> obj = ProjectUtility.SearchByKey(Request.Url.Segments[3].ToString());
return Json(obj);
}
my search function
public IEnumerable<Project> SearchByKey(string SearchKey)
{
var context = new MountSinaiEntities1();
var matches = from m in context.Project
where m.projectName.Contains(SearchKey)
select m;
return matches;
}
my java script code
function Search() {
var GetURL = location.protocol + "//" + location.host + "/ProjectUtility/SearchAjax";
$.ajax({
cache: false,
type: "POST",
async: false,
url: GetURL,
dataType: "json",
success: function (Projects) {
}
});
}
Search TextBox
<input type="text" id="inputForm" name="txtSearch" placeholder="Search" önkeyup="Search()" />
Code to bind WebGrid
var grid = new WebGrid(Model, defaultSort: "projectName", rowsPerPage: 10, canPage: true, canSort: true, ajaxUpdateContainerId: "Grid");