TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
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.
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);
Reply
Answers (
3
)
Update value from a model with one from another model
Two Factor authentication in Web Api mvc