Guest User

Guest User

  • Tech Writer
  • 64
  • 2.8k

Show items from SelectList with condition

May 7 2021 8:23 AM
I want to show in the List only the items where "DataSfarsit" < Datetime.Now.
 
How can I do that?
 
 controller: 
  1. [Authorize]  
  2.         public ActionResult Create()  
  3.         {  
  4.             
  5.             ViewBag.IDLicitatie = new SelectList(db.Licitatie, "IDLicitatie""IDLicitatie").Where(...);  
  6.             ViewBag.IdUser = db.Useri.FirstOrDefault(x => x.Email == User.Identity.Name).IdUser;  
  7.              
  8.             return View();  
  9.         }  
 The model:
 
  1. public partial class Licitatie  
  2.    {  
  3.        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage""CA2214:DoNotCallOverridableMethodsInConstructors")]  
  4.        public Licitatie()  
  5.        {  
  6.            this.Oferte = new HashSet<Oferte>();  
  7.             
  8.        }  
  9.      
  10.        public int IDLicitatie { getset; }  
  11.        public System.DateTime DataPornire { getset; }  
  12.        public System.DateTime DataIncheiere { getset; }  
  13.        public decimal PretInitial { getset; }  
  14.        public int IDProdus { getset; }  
  15.      
  16.        public virtual Produse Produse { getset; }  
  17.        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage""CA2227:CollectionPropertiesShouldBeReadOnly")]  
  18.        public virtual ICollection<Oferte> Oferte { getset; }  
 
So basically I want the  IDLicitate = "4" from there to not appear because it has DataSfarsit < Datetime.now.

Answers (1)