How do I filter products based on which checkbox category is selected? for example if "Pistols" checkbox is selected it only shows pistols.
view code:
<div style="background-color: #454545;">
<ul class="category-ul">
<li>
<input type="checkbox" id="pistol" name="Pistols">
<label for="pistol">Pistols</label>
</li>
<li>
<input type="checkbox" id="smg" name="SMGs">
<label for="smg">SMGs</label>
</li>
<li>
<input type="checkbox" id="rev" name="Revolvers">
<label for="rev">Revolvers</label>
</li>
<li>
<input type="checkbox" id="shotgun" name="Shotguns">
<label for="shotgun">Shotguns</label>
</li>
<li>
<input type="checkbox" id="assault" name="AssaultRifles">
<label for="assault">Assault Rifles</label>
</li>
<li>
<input type="checkbox" id="rifle" name="Rifles">
<label for="rifle">Rifles</label>
</li>
</ul>
</div>
controller code:
public async Task<IActionResult> weapons(decimal MinPrice, decimal MaxPrice)
{
var firearms = from s in _context.Firearm
select s;
var max = firearms.Max(i => i.Price);
MaxPrice = max;
ViewData["MinimumPrice"] = MinPrice;
ViewData["MaximumPrice"] = MaxPrice;
ViewData["Maximum"] = MaxPrice;
if (MinPrice > 0 || MaxPrice < max)
{
firearms = firearms.Where(s => s.Price > MinPrice
&& s.Price < MaxPrice);
}
return View(await firearms.AsNoTracking().ToListAsync());
}
model code:
public class Firearm
{
[Key]
public int id { get; set; }
public string Manufacturer { get; set; }
public string Model { get; set; }
public decimal Price { get; set; }
public string Category { get; set; }
public string Caliber { get; set; }
public string Barrel { get; set; }
public string Magazine { get; set; }
public string Sight { get; set; }
public string? PicturePath { get; set; }
}