How to show all data from table section when the Active field value = true RRS feed

  • Question

  • Problem

    I need to show all data from table section where Active field = true in table section

    my code as following

    namespace UniversityData.Models
        public partial class Section
            public Section()
            public int SecID { get; set; }
            public string SecName{ get; set; }
            public bool Active { get; set; }

    my Index view as following

                @foreach (var item in Model)

    In controller section in function index i write following

    How to make index function inside section controller show only all records from table section if value of Active field = true

      public ActionResult Index()
                return View(db.Sections.ToList());

    Wednesday, November 16, 2016 12:19 AM

All replies

  • Hi eng-ahmed-salah,

    According to your description, it seems that you want to retrieve the value of Active field = true, if it is the case, please add where conduction in your code, like this: 

    public ActionResult Index()
         return View(db.Sections.Where(Where(x => x.Active == true).ToList());

    Best regards,

    Cole Wu

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Wednesday, November 16, 2016 9:46 AM