Reputation: 1
I am working on my semester end project.
Application was working fine, but when I added product function it worked once. Then I started getting null exception in the function. Now i am also getting same error in log in function as well.
I am getting this error:
This is my code:
[HttpPost]
public ActionResult LogIn(User ur, string ReturnUrl)
{
if (isValid(ur) == true)
{
FormsAuthentication.SetAuthCookie(ur.UserName, false);
Session["Usrname"] = ur.UserName;
if (ReturnUrl != null)
{
return Redirect(ReturnUrl);
}
else
{
return RedirectToAction("Index", "Dashboard");
}
}
else
{
ViewBag.msg = "Email Or Password is incorrect";
return View();
}
}
bool isValid(User ur)
{
var cred = u_DB.Users.Where(model => model.UserEmail == ur.UserEmail && model.UserPassword == ur.UserPassword).FirstOrDefault();
if (cred != null)
{
return true;
}
else
{
return false;
}
}
Upvotes: 0
Views: 80
Reputation: 189
Try using Refresh method.
try{
DB.SaveChanges();
}
catch(OptimisticConcurrencyException){
DB.Refresh(RefreshMode.ClientWins, yourentity);
DB.SaveChanges();
}
And for the NullException Error in this Image, try the below code line.
List<SubCategory> Scat = P_DB.subCategories!.toList();
Hope this helps. If it works let me know.
Upvotes: 3