Thabo Happy

Thabo Happy

  • NA
  • 105
  • 15.3k

asp.net mvc 5 count registered users and return the number

Oct 10 2018 4:21 PM
Hello  am trying to count registered users from my database
so i came up with something like this:
  1. public class HomeController : Controller  
  2. {  
  3.     private ApplicationDbContext db = new ApplicationDbContext();  
  4.     
  5.     public ActionResult Index()  
  6.     {  
  7.        if(User.IsInRole("Tutor"))  
  8.         {  
  9.              ViewData["TutorCount"] = db.Users.Count();  
  10.          }  
  11.          else  
  12.          {  
  13.                ViewData["StudentCount"] = db.Users.Count();  
  14.           }  
  15.            
  16.         return View();  
  17.     }          
  18. }  
 but doesn't seem to be working 
any help or improvement please
 
i ll apriciate any help. 

Answers (5)