My requirement is like grid should not be loaded on page load and on click of search button it has to call WebAPI to get records, below is my code,
@Html.DropDownList("SearchByEmployeeDropDown", new SelectList(ViewBag.EmpName, "Id", "Name"), "Select tag", htmlAttributes: new { @class = "emp-dropdown" })
<input type="button" id="btnsearchbyemp" value="Search" onclick="BindGrid()">
@(Html.Kendo().Grid<Employess>()
.Name("Searchgrid")
.Columns(columns =>
{
columns.Bound(c => c.EmpId).Width("15%").HtmlAttributes(new { title = " #= EmpId #" });
columns.Bound(c => c.EmpName).Width("15%").HtmlAttributes(new { title = " #= EmployeeName# " });
})
.AutoBind(false)
.Filterable()
.Selectable()
.Scrollable()
.Sortable()
.Pageable()
.Resizable(c=> c.Columns(true))
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Url(**I want to construct URL based on search button click**).Type(HttpVerbs.Get))
) )
//Function to read grid on search button click.
function BindGrid() {;
var param1 = $("# SearchByEmployeeDropDown").val();
$("#Searchgrid").data("kendoGrid").dataSource.read();
$("#Searchgrid").data("kendoGrid").refresh();
}
//WebAPI “/api/Search/EmployeeSearch”
public DataSourceResult
GetEmployeeSearchs([ModelBinder(typeof(DataSourceRequestModelBinder))] DataSourceRequest dataRequest, string empId)
{
IEnumerable<Employee> searchlist = null;
if (empId == null)
{ return null;
}
return searchService.GetEmployeeDetails(empId);
}
My API url looks like ”/api/Search/EmployeeSearch/?empId=<<Selected value of combo>>”
I have two question:
1. Initially my api will return null value how will I bind null to kendo grid?
2. How to pass data source URL on search button click?
Please help me to resolve this. Thanks in advance!!