Permalink
Browse files

Enable graceful degradation of our Ajax filtering.

  • Loading branch information...
gilles-leblanc committed Nov 3, 2016
1 parent c19ce07 commit 1a19bb1595677c0bb6590855f0bc96a4bf50d24f
Showing with 7 additions and 3 deletions.
  1. +5 −2 Ajax2/Controllers/HomeController.cs
  2. +2 −1 Ajax2/Views/Home/Index.cshtml
@@ -19,15 +19,18 @@ public ActionResult Index()
}
[HttpPost]
public PartialViewResult FilterDepartmentsAjax(DepartmentsModel model)
public ActionResult FilterDepartmentsAjax(DepartmentsModel model)
{
var updatedModel = new DepartmentsModel
{
Filtered = model.Filtered,
Departments = GetDepartments(filtered: model.Filtered),
};
return PartialView("DepartmentsTablePartial", updatedModel);
if (Request.IsAjaxRequest())
return PartialView("DepartmentsTablePartial", updatedModel);
return View("Index", updatedModel);
}
private IEnumerable<DepartmentModel> GetDepartments(bool filtered)
@@ -17,7 +17,7 @@
{
<label>Filter: </label>
@Html.CheckBoxFor(model => model.Filtered, new { onclick = "$(this).parents('form:first').find(':submit')[0].click();" })
<input type="submit" value="Submit" style="display: none" />
<input id="input-filter" type="submit" value="Submit" />
}
<div id="department-table">
@@ -28,6 +28,7 @@
{
<script type="text/javascript">
$(document).ready(function () {
$('#input-filter').hide();
$('#deparment-table').DataTable();
});

0 comments on commit 1a19bb1

Please sign in to comment.