Guest User

Guest User

  • Tech Writer
  • 64
  • 2.8k

Compare in a single controller two models

Apr 28 2021 4:15 PM
Hello, I have to make an auction website and in Users_Offers I need to make sure that they don't bid less that "Start Price"  from Auctions
 
 
 
 
This is the controller , but when I run the application the "oferte.Licitatie.PretInitial " ( which is Auction.StartPrice ) is null and I get an error "Object reference not set to an instance of an object."  I tried to write it like : db.Auction. but then StartPrice doesn't appear anymore.
 
 
 
  1. public ActionResult Create([Bind(Include = "Oferteid,IDLicitatie,IdUser,ValoareBid,DataBid")] Oferte oferte)  
  2.         {  
  3.               
  4.             if (ModelState.IsValid)  
  5.             { if (oferte.Licitatie.PretInitial < oferte.ValoareBid)  
  6.                 {  
  7.                     db.Oferte.Add(oferte);  
  8.                     db.SaveChanges();  
  9.                     return RedirectToAction("Index""Licitaties");  
  10.                 }  
  11.                 else { ViewBag.notificare = "Trebuie o suma mai mare decat pretul initial"; }  
  12.                  
  13.             }  
  14.   
  15.             ViewBag.IDLicitatie = new SelectList(db.Licitatie, "IDLicitatie""IDLicitatie", oferte.IDLicitatie);  
  16.             ViewBag.IdUser = db.Useri.FirstOrDefault(x => x.Email == User.Identity.Name).IdUser;   
  17.             return View(oferte);  
 
 
 
 

Answers (3)