I've provided a solution in your previous post.
Please do not create duplicate posts. If there is a problem with the solution in your previous post then explain why the code does not meet your expectations.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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);
}
I've provided a solution in your previous post.
Please do not create duplicate posts. If there is a problem with the solution in your previous post then explain why the code does not meet your expectations.
I have added 3 button and need to pass either True if button1 or False if button2 or NULL if button3.
Please write your code to show how you have added the buttons, explain what your issue is, and let us know what you need to know to solve the issue, while keeping in mind that many answers have already been given to you in the previous questions: