0

For my website, I am able to display every detail of the Account Table in my database. My AccountStatus has 2 values inside the database; "Approved" and "Rejected". However, I want to display the details on my website only if the value of the AccountStatus is "Approved".

I am currently using ASP.net core MVC with EF core and SQL server.

Model:

public class AccountModel
   {
       [Key]
       public Guid AccountID { get; set; }

       public DateTime AccountCreationDateTime { get; set; }

       public string AccountStatus { get; set; }
   }

Controller:

public async Task<IActionResult> Account()
       {
           return View(await _context.Account.ToListAsync());
       }

1 Answer 1

2
public async Task<IActionResult> Account()
       {
           return View(await _context.Account.Where(s => s.AccountStatus == "Approved").ToListAsync());
       }

I would advice you to learn some more about the basics of queries an linq: https://www.entityframeworktutorial.net/efcore/querying-in-ef-core.aspx

PS: Better to put your AccountStatus in a seperate table instead of using a string

Sign up to request clarification or add additional context in comments.

1 Comment

Sorry, I am new to Asp.net. Why is it better to put the AccountStatus in a separate table?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.