Hi. I've been trying to figure out why my DataTable bound grid (with dynamic columns and Ajax data source) was erroring whenever I clicked a column heading to sort it. This has been driving me crazy as my view and controller code is very similar to the binding to data table sample code you provide.
I finally discovered the problem occurs whenever a column has certain characters in the column name (e.g. a space, a period or a hash character). If one of these characters is present the request becomes a GET rather than a POST which results in a 404 error as JSON results are not permitted via GET by default.
Please let me know how I can have column names with these characters as they are required for our column names. Thanks!
View code:
Controller code:
I finally discovered the problem occurs whenever a column has certain characters in the column name (e.g. a space, a period or a hash character). If one of these characters is present the request becomes a GET rather than a POST which results in a 404 error as JSON results are not permitted via GET by default.
Please let me know how I can have column names with these characters as they are required for our column names. Thanks!
View code:
@(Html.Kendo().Grid(Model)
.Name(
"grid"
)
.Columns(columns =>
{
foreach
(System.Data.DataColumn column
in
Model.Columns)
{
columns.Bound(column.ColumnName);
}
})
.Pageable()
.Sortable()
.DataSource(dataSource => dataSource
.Ajax()
.Model(model =>
{
foreach
(System.Data.DataColumn column
in
Model.Columns)
{
model.Field(column.ColumnName, column.DataType);
}
})
.Read(read => read.Action(
"Read"
,
"Reports"
))
)
)
public
ActionResult Read([DataSourceRequest] DataSourceRequest request)
{
DataTable products = Products();
return
Json(products.ToDataSourceResult(request));
}