kindly give me code for filter hall according to price through controller of our event Management System in .net mvc C#
Loading
kindly give me code for filter hall according to price through controller of our event Management System in .net mvc C#
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Rajkiran SwainRank #165 · 14.4K reputationPosted May 22, 2023, 9:59 AM EDT
public ActionResult FilterHallsByPrice(decimal maxPrice) { // Retrieve halls from your data source based on the maximum price var filteredHalls = db.Halls.Where(h => h.Price <= maxPrice).ToList(); // Return the filtered halls to the view return View(filteredHalls); }@model List Filtered Halls @if (Model.Count > 0) { foreach (var hall in Model) { @hall.Name Price: @hall.Price } } else { No halls found. }Make sure to adjust the code according to your actual model names, database context (
db), and any additional properties or requirements specific to your event management system.The code above filters halls based on the maximum price provided by the user and displays the filtered results in the view.
Naimish MakwanaRank #324 · 7.7K reputationPosted May 22, 2023, 11:52 PM EDT
// HallsController.cs using System.Collections.Generic; using System.Linq; using System.Web.Mvc; using YourEventManagementSystem.Models; // Assuming you have a Hall model public class HallsController : Controller { private readonly YourEventManagementContext db = new YourEventManagementContext(); // Assuming you have a database context // GET: Halls public ActionResult Index(decimal? maxPrice) { // Fetch all halls from the database IQueryable halls = db.Halls; // Apply filtering based on the maximum price if provided if (maxPrice.HasValue) { halls = halls.Where(h => h.Price <= maxPrice.Value); } // Return the filtered halls to the view return View(halls.ToList()); } }Thanks