This question is locked. New answers and comments are not allowed.
I have a project that I am converting an existing ASP.NET website to an ASP.NET MVC site. This conversion is more for my own experience, but if I can accomplish this, the additional changes will be so much simpler.
Here is my scenario. I have a stored procedure that returns a dynamically created dataset (columns returned are specific to the input parameters). When I use ASP.NET and a Telerik RadGrid control, it binds perfectly. However when I try to port this logic over to MVC I get multiple errors.
I initially attempted to bind the data is a similar way that I bind the data using ASP.NET. The data I retrieve comes from a webmethod from a legacy ASP.NET 2.0 web service. So due to that, I am stuck with dealing with the DataSet it returns.
I have tried to return the first table in the DataSet (using the AsEnumerable method) and then use the AutoGenerate method in the view to automatically generate the columns.
Controller's code
View's Code
This logic will return the grid, and will generate the pager correctly with the total number of rows and everything. However, it shows no columns nor column headers.
When I change up the controller to add the following
and then add this to the view
I get this error.
Is there a setting that I'm forgetting that will fix this issue?
Thanks.
Russ
Here is my scenario. I have a stored procedure that returns a dynamically created dataset (columns returned are specific to the input parameters). When I use ASP.NET and a Telerik RadGrid control, it binds perfectly. However when I try to port this logic over to MVC I get multiple errors.
I initially attempted to bind the data is a similar way that I bind the data using ASP.NET. The data I retrieve comes from a webmethod from a legacy ASP.NET 2.0 web service. So due to that, I am stuck with dealing with the DataSet it returns.
I have tried to return the first table in the DataSet (using the AsEnumerable method) and then use the AutoGenerate method in the view to automatically generate the columns.
Controller's code
return View(ds.Tables[0].AsEnumerable());View's Code
@{ Html.Telerik().Grid(Model) .Name("Grid") .Columns(c => c.AutoGenerate(true)) .Pageable() .Render();}This logic will return the grid, and will generate the pager correctly with the total number of rows and everything. However, it shows no columns nor column headers.
When I change up the controller to add the following
private GridColumnSettings[] GetGridColumns(DataTable dataTable){ GridColumnSettings[] gridColumnSettings = new GridColumnSettings[dataTable.Rows.Count]; for (int i = 0; i < dataTable.Rows.Count;i++ ) { gridColumnSettings[i] = new GridColumnSettings { Member = dataTable.Rows[i].Field<string>("DBFIELD"), Title = dataTable.Rows[i].Field<string>("CAPTION"), Format = ( (dataTable.Rows[i].Field<int>("NDATATYPE") == 4) ? "{0:c}" : (dataTable.Rows[i].Field<int>("NDATATYPE") == 5) ? "{0:d}" : "{0}" ), Width = "20em", }; } return gridColumnSettings;}and then add this to the view
.Columns(columns => columns.LoadSettings((IEnumerable<GridColumnSettings>)ViewData["Columns"]))I get this error.
'object' does not contain a definition for 'Column0'
Is there a setting that I'm forgetting that will fix this issue?
Thanks.
Russ