控制器自動完成
public class HomeController : Controller
{
public JsonResult UniversalSearch()
{
List<UniversalSearchBar> EmployeeDetails = new List<UniversalSearchBar>();
EmployeeDetails.Add(new UniversalSearchBar() { EmployeeName = "Abishek", EmployeeID = "SF2532", EmailID = "[email protected]" });
EmployeeDetails.Add(new UniversalSearchBar() { EmployeeName = "Bharath", EmployeeID = "SF2010", EmailID = "[email protected]" });
EmployeeDetails.Add(new UniversalSearchBar() { EmployeeName = "Roshini", EmployeeID = "SF3052", EmailID = "[email protected]" });
EmployeeDetails.Add(new UniversalSearchBar() { EmployeeName = "Kathir", EmployeeID = "SF5572", EmailID = "[email protected]" });
EmployeeDetails.Add(new UniversalSearchBar() { EmployeeName = "Ragu", EmployeeID = "SF7582", EmailID = "[email protected]" });
EmployeeDetails.Add(new UniversalSearchBar() { EmployeeName = "Sri", EmployeeID = "SF3456", EmailID = "[email protected]" });
EmployeeDetails.Add(new UniversalSearchBar() { EmployeeName = "Guru", EmployeeID = "SF2890", EmailID = "[email protected]" });
var Employees = EmployeeDetails;
return Json(Employees, JsonRequestBehavior.AllowGet);
}
}
查看
<select class="form-control" id="searchFilterList" style="width:200px!important" onchange="changeSearchBarID()">
<option value="employeeName">Employee Name</option>
<option value="employeeID">Employee ID</option>
<option value="emailID">Email ID</option>
</select>
<input class="form-control" type="text" placeholder="Search..." id="EmployeeNameSearch"; style="max-width:800px!important">
腳本
var autocomplete;
$(function() {
// declaration
var options = {
//how to render json data from controller here?//
};
$('#EmployeeNameSearch').ejAutocomplete({
dataSource: options,
width: "800",
template: '<div class="txt"> ${EmployeeName} </div>' +
'<div class="txt"> ${EmailID} </div>'
});
});
在這裏,我有下拉與三類1)員工姓名2)員工ID 3)電子郵件ID。 默認情況下,當我在搜索欄中輸入內容時,它應該在建議中顯示員工姓名以及電子郵件ID。
如果我在類別中選擇員工ID和搜索應該找到員工的姓名與輸入員工ID和顯示員工姓名和建議以下電子郵件ID類型的東西
如果我選擇電子郵件ID類別和搜索應該找到員工姓名輸入相關EMAIL ID和顯示員工姓名和建議
以下電子郵件ID因爲我是新來這個,請鍵入索姆東西我清楚地解釋了我。
我應該在routeconfig中添加一些東西,當我使用它。
請爲此類需求添加WebApi。 –