Here's my Combobox in Razor format:
@(Html.Kendo().ComboBox()
.Name("cmbQuarter")
.DataTextField("QTR")
.DataValueField("QTR")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetBuyQuarter", "BuyBuilder"); //Set the Action and Controller name
})
.ServerFiltering(true); //If true the DataSource will not filter the data on the client.
})
.SelectedIndex(0) //Select first item.
)
My Controller GetBuyQuarter Function:
public ActionResult GetBuyQuarter([DataSourceRequest]DataSourceRequest request)
{
DataTable dt = new DataTable();
List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
Dictionary<string, object> row = default(Dictionary<string, object>);
string conn = ConfigurationManager.ConnectionStrings["DevConnString"].ConnectionString;
using (SqlConnection con = new SqlConnection(conn))
{
using (SqlCommand cmd = new SqlCommand("select * from QTRLIst where(startdate > DateAdd(yy, -2, getdate()) And startdate < DateAdd(yy, 1, getdate())) order by StartDate desc ", con))
{
con.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
con.Close();
foreach (DataRow dr in dt.Rows)
{
row = new Dictionary<string, object>();
foreach (DataColumn col in dt.Columns)
{
row.Add(col.ColumnName, dr);
}
rows.Add(row);
}
}
}
return Json(rows, JsonRequestBehavior.AllowGet);}
I do not see any data in the combobox. If i changed the return to Json(dt.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
i get this error. Unhandled exception at line 11, column 15864 in http://localhost:52493/Scripts/kendo/2014.1.415/kendo.all.min.js
0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'slice'
@(Html.Kendo().ComboBox()
.Name("cmbQuarter")
.DataTextField("QTR")
.DataValueField("QTR")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetBuyQuarter", "BuyBuilder"); //Set the Action and Controller name
})
.ServerFiltering(true); //If true the DataSource will not filter the data on the client.
})
.SelectedIndex(0) //Select first item.
)
My Controller GetBuyQuarter Function:
public ActionResult GetBuyQuarter([DataSourceRequest]DataSourceRequest request)
{
DataTable dt = new DataTable();
List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
Dictionary<string, object> row = default(Dictionary<string, object>);
string conn = ConfigurationManager.ConnectionStrings["DevConnString"].ConnectionString;
using (SqlConnection con = new SqlConnection(conn))
{
using (SqlCommand cmd = new SqlCommand("select * from QTRLIst where(startdate > DateAdd(yy, -2, getdate()) And startdate < DateAdd(yy, 1, getdate())) order by StartDate desc ", con))
{
con.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
con.Close();
foreach (DataRow dr in dt.Rows)
{
row = new Dictionary<string, object>();
foreach (DataColumn col in dt.Columns)
{
row.Add(col.ColumnName, dr);
}
rows.Add(row);
}
}
}
return Json(rows, JsonRequestBehavior.AllowGet);}
I do not see any data in the combobox. If i changed the return to Json(dt.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
i get this error. Unhandled exception at line 11, column 15864 in http://localhost:52493/Scripts/kendo/2014.1.415/kendo.all.min.js
0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'slice'