I am able to pass a Search string and a Sort string parameter from Index.cshtml to ActionResult Index in StudentsControler.cs. I have added 3 button and need to pass either True if button1 or False if button2 or NULL if button3. It is much like Search but Boolean (True or False) in buttons’ case.
How do I do it in the code below?
Index.cshtml:
<div class="btn-group" role="group" aria-label="Filter by IsFeatured">
<button type="button" class="btn btn-primary @((ViewBag.IsFeaturedFilter == null) ? "active" : "")"
onclick="location.href='@Url.Action("Index", "Students")'">
All
</button>
<button type="button" class="btn btn-primary @((ViewBag.IsFeaturedFilter == true) ? "active" : "")"
onclick="location.href='@Url.Action("Index", "Students", new { isFeaturedFilter = true })'">
Deleted
</button>
<button type="button" class="btn btn-primary @((ViewBag.IsFeaturedFilter == false) ? "active" : "")"
onclick="location.href='@Url.Action("Index", "Students", new { isFeaturedFilter = false })'">
Not Deleted
</button>
</div>
StudentsController.cs:
public ActionResult Index(string sortOrder, string searchString)
{
var students = from m in db.Students select m;
ViewData["NameSortParm"] = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
switch (sortOrder)
{
case "name_desc":
students = subjects.OrderByDescending(s => s.StudentLName );
break;
default:
students = subjects.OrderBy(s => s.StudentFName);
break;
}
if (!String.IsNullOrEmpty(searchString))
{
if (!string.IsNullOrEmpty(searchString))
{
students = students .Where(s => s.StudentLName == searchString
|| s.StudentFName.Contains(searchString)
);
}
}
ViewBag.CurrentSearch = searchString;
return View(students);
}