Reputation: 747
Whole error in popup: "Error! The requested URL Returned 500 - Internal server error"
Edit This is partly fixed, I moved the TempData to the index function and added the parameters there as well. However, this has broken my sorting functionality as well ( .Sortable(sorting => sorting.SortMode(GridSortMode.SingleColumn)) End Edit
I've no idea why this error is occurring and have spent way too much time on it already, so to start with I'll just post the code and hope someone can help.
Controller:
[GridAction(EnableCustomBinding = true)]
public ActionResult GetTimetables(int moduleId, ModuleType moduleType)
{
TempData["ModuleId"] = moduleId;
IList<TimetableViewModel> timetableViewModels =
//TODO: Don't hardcode this
_timetableService.GetTimetableEntriesAssociatedWithModule(moduleId, moduleType);
return View(new GridModel
{
Data = timetableViewModels,
});
}
Model (Probably doesn't matter though):
public class TimetableViewModel : BaseViewModel
{
public int Id { get; set; }
public string Date { get; set; }
public string SessionTimePeriod { get; set; }
public string RoomName { get; set; }
public int NumberOfResources { get; set; }
public string Notes { get; set; }
}
}
View (too long to paste all of it and not needed)
@(Html.Telerik().Grid(Model)
.Name("TimetableGrid")
.PrefixUrlParameters(false)
.Columns(columns =>
...
.DataBinding(dataBinding => dataBinding.Ajax().Select("GetTimetables", "Manage", new { moduleId = TempData["ModuleId"], moduleType = ModuleType.UnitOfLearning }))
//.Pageable(paging => paging.Total(Model.entryCount).PageSize(25))
.Sortable(sorting => sorting.SortMode(GridSortMode.SingleColumn)))
@Html.Telerik().ScriptRegistrar().jQuery(false).jQueryValidation(false)
Upvotes: 0
Views: 2383
Reputation: 834
I had similar problem and Fiddler made me conclude that the problem is with your databinding statements: dataBinding.Ajax().Select(...)
Problem is with deferred LINQ execution. This solution, adding ToList at end of LINQ query, helped me: asp.net MVC 4 Telerik Grid Ajax issue
Upvotes: 1
Reputation: 5732
There are a couple things that look like they might be the cause of errors. First there is a comma at the end of the Data statement.
return View(new GridModel
{
Data = timetableViewModels,
});
should be
return View(new GridModel
{
Data = timetableViewModels
});
or you could do this if you want
return View(new GridModel(timetableViewModels);
Second, I think, in the view you need to tell the grid your data type for Ajax databinding.
@(Html.Telerik().Grid(Model)
.Name("TimetableGrid")
should be
@(Html.Telerik().Grid<TimetableViewModel>()
.Name("TimetableGrid")
Also, if you are able, you might want to try putting a breakpoint in the controller to see if the data is loaded into the timetableViewModels variable properly.
Upvotes: 1