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;
}
}
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.