Ar Vhin

Ar Vhin

  • NA
  • 498
  • 90k

MVC: How to display only Active customer

Jul 29 2018 11:06 PM
How to display only Active customer(isActive : true) in mvc.
 

Answers (3)

1
Rajesh Gami

Rajesh Gami

  • 81
  • 24.4k
  • 1.3m
Jul 29 2018 11:12 PM
try this
 
in model
 
  1. public class CustomerMaster  
  2.    {   
  3.           //- your field  
  4.    }  
  5.   
  6. public class CustomerMasterContext : DbContext  
  7.    {  
  8.        public CustomerMasterContext() : base("Connectionstring_Name")  
  9.        { }  
  10.        public DbSet<CustomerMaster> CustomerMaster { getset; }  
  11.      
  12.    } 
 now Controller
  1. public class AdminCustomerController : Controller  
  2.     {  
  3.          CustomerMasterContext _customerContext = new CustomerMasterContext();  
  4.   
  5.              public ActionResult Index()  
  6.             {   
  7.                 var active = _customerContext.CustomerMaster.Where(b=>b.CSMIsActive== true).ToList();  
  8.                return View(active);  
  9.              }  
  10.      } 
 now add view and show output.
 
 
Accepted Answer
1
Jenith Thakkar

Jenith Thakkar

  • 349
  • 5k
  • 27.9k
Jul 29 2018 11:11 PM
For that you can use Linq Queries
Like This 

var CustomerList=db.Customers.where(l=>l.IsActive==true).toList();

And in VIewSIde Get this Customer List


If you still facing any issue then provide your code i will tell you the solution
0
Ar Vhin

Ar Vhin

  • 0
  • 498
  • 90k
Jul 29 2018 11:23 PM
thank u both of u guys rajesh and jenith