Search code examples
c#asp.net-mvcasp.net-mvc-views

Create a view (index) to show a list of records for a specific id?


Morning folks,

Im using c# within my mvc project. i have an index view that lists household members.

This works fine and pulls back the all of the records in the database.

 public ActionResult Index()
    {
        List<Household> houseRecords = db.Households.ToList();

        return View(houseRecords);
    }

I have created another list view page named ListMembers(), This list is based on family members and so i want this view to pull back records specific to the referral i have created (ClientId).

I have thought that i might be able to add a where clause to my List code and base this on the ClientId but im not 100% sure this will work.

 List<Household> houseRecords = db.Households.ToList().Where(x => x.ClientId = x.id);

Can anyone point me in the right direction?

Regards Betty


Solution

  • it will work as i believe but you can do it this way

     var  houseRecords = db.Households.Where(x => x.ClientId = x.id).ToList(); 
    

    i think it more better to do the where before get the final list