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.
- public ActionResult Create([Bind(Include = "Oferteid,IDLicitatie,IdUser,ValoareBid,DataBid")] Oferte oferte)
- {
-
- if (ModelState.IsValid)
- { if (oferte.Licitatie.PretInitial < oferte.ValoareBid)
- {
- db.Oferte.Add(oferte);
- db.SaveChanges();
- return RedirectToAction("Index", "Licitaties");
- }
- else { ViewBag.notificare = "Trebuie o suma mai mare decat pretul initial"; }
-
- }
-
- ViewBag.IDLicitatie = new SelectList(db.Licitatie, "IDLicitatie", "IDLicitatie", oferte.IDLicitatie);
- ViewBag.IdUser = db.Useri.FirstOrDefault(x => x.Email == User.Identity.Name).IdUser;
- return View(oferte);