Reputation: 1
I'm having some issues with some data filtering ; I want, from the following dropdown menu, to be able to display a list of projects by approval or not.
When the user creates a new project one of the fields is "approved", which is a boolean. That checkbox is left not checked and when the project has a Go the user picks that checkbox as an approved project.
Basically, I want, when the user picks the option "Approved", to be redirected to the list of already approved projects.
How can I do that?
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Project Execution <span class="caret"></span></a>
<ul class="dropdown-menu">
<li> @Html.ActionLink("Approved", "Index", "NEWPROJECTs")</li>
<li role="separator" class="divider"></li>
<li>@Html.ActionLink("On Going", "Index", "NEWPROJECTs")</li>
<li role="separator" class="divider"></li>
<li>@Html.ActionLink("List", "Index", "PROJECTEXECUTIONs")</li>
</ul>
Upvotes: 0
Views: 1368
Reputation: 76547
Using Route Parameters
If you have a single controller action that handles one or more of these operations, then you'll likely need to supply a route value to determine what data you should be filtering by:
public ActionResult NewProjects(string filter)
{
// Check the filter that was used and filter the content that you
// will pass to the view accordingly
// Get your projects prior to filtering
var projects = _context.Projects;
switch (filter)
{
case "ONGOING":
projects = projects.Where(p => p.Status == "ONGOING");
break;
default:
projects = projects.Where(p => p.Status == "APPROVED");
break;
}
return View(projects);
}
Then when you build your Action Links, simply specify the filter
as a route value so that your controller action can consume it and properly filter your data:
<li>
@Html.ActionLink("Approved", "Index", "NEWPROJECTs", new { filter = "APPROVED"})
</li>
<li role="separator" class="divider"></li>
<li>
@Html.ActionLink("On Going", "Index", "NEWPROJECTs", new { filter = "ONGOING"})
</li>
Upvotes: 1