I have an asp.net dashboard page that shows some tables and statistics, along with a filter panel with some checkboxes and a date range picker. I wrote jQuery to fire whenever a checkbox is clicked. The jQuery uses an Ajax POST to send the filter settings to the controller, which then queries the DB, applies the filter settings, creates a new page model, and sends it to the view. At this point I would like the razor view to be newly created and the browser to show a newly rendered page, but nothing changes and I get a 500 error in the console, probably because the controller isn't sending an appropriate response. Is there a better way to achieve what I'm trying to do?
The data is reaching the controller successfully and the new page model is being created correctly. I'm at a loss for what to do after this point.
javascript:
function sendFilterData() {
var checks = getFilterSettings(); //stringified JSON
$.ajax({
method: 'POST',
url: '@Url.Action("ApplyDashboardFilter", "Home")',
data: {
checks: checks, start: globalstart.format("YYYY-MM-DD HH:mm:ss"), end: globalend.format("YYYY-MM-DD HH:mm:ss") },
success: function (response) {
//???
},
failure: function (response) {
console.log(response);
}
});
}
C#
public IActionResult ApplyDashBoardFilter(string checks, DateTime start, DateTime end)
{
var filters = JsonConvert.DeserializeObject<List<FilterItem>>(checks);
ViewModel vm = new ViewModel();
foreach(var f in filters)
{
vm.AddFilter(f);
}
vm.StartDate = start;
vm.EndDate = end;
return Dashboard(vm);
}
public IActionResult Dashboard(ViewModel model)
{
//Get data and apply filters
return View(model);
}