I am building a reports page, which has multiple filters, and when the user selects 0 to all, it shows all columns, and filters through all data. I'm not sure how to join filters when more than one is selected. Sample code is below, I have posted only the relevant code because it is very lengthy, and the controller is pulling from the model, which is where 'IssueViewModel' is coming from. I did find Filter/Search using Multiple Fields - ASP.NET MVC but it required me to change too much of my code because of variable issues for what I have already written. Thank you!
Controller:
public ActionResult Reports(string JIssue, string Status)
{
string EX = "EX";
var Issues = db.Data.Select(i => new IssueViewModel { });
if (JIssue == "2"){
Issues = db.Data.Where(d => d.Column.Contains(EX)).Select(i => new IssueViewModel
{
Name = i.Name,
Description = i.Description,
Key = i.Key,
LastUpdate = i.LastUpdate,
ID = i.ID,
IssueType = i.IssueType,
ProgrammingStatus = i.ProgrammingStatus
}); }
if (Status == "2"){
Issues = db.Data.Where(d => d.Column2.Contains(1)).Select(i => new IssueViewModel
{
Name = i.Name,
Description = i.Description,
Key = i.Key,
LastUpdate = i.LastUpdate,
ID = i.ID,
IssueType = i.IssueType,
ProgrammingStatus = i.ProgrammingStatus
}); }
ViewBag.Issues = Issues.ToList();
return View();
View:
@Html.DropDownList("JIssue", new List<SelectListItem> {
new SelectListItem { Text = "All", Value = "1", Selected = true},
new SelectListItem { Text = "EX", Value = "2"},
new SelectListItem { Text = "EXX", Value = "3"},
new SelectListItem { Text = "EZX", Value = "4"},
new SelectListItem { Text = "ABC", Value = "5"},
new SelectListItem { Text = "BCD", Value = "6"},
new SelectListItem { Text = "CDE", Value = "7"},
}, "Select Project")