public ActionResult LogIn()
{
return View();
}
[HttpPost]
public ActionResult LogIn(UserLogins p, UserRecipe u)
{
////var s = context.plate.FirstOrDefault( x => x.Email.Equals(p.Email) && x.Password.Equals(p.Password));
var details = (from userlist in context.plate
where userlist.Email == p.Email && userlist.Password == p.Password
select new
{
userlist.UserID,
userlist.Name,
userlist.Email
});
if (details != null)
{
// Session["User"] = s;
Session["User"] = p.Email;
Session["Name"] = details.FirstOrDefault().Name;
Session["UserId"] = details.FirstOrDefault().UserID;
u.UserId = Convert.ToInt32(Session["UserId"]);
context.SaveChanges();
TempData["Added"] = "You are successfully Logged in";
return RedirectToAction("ShowProducts");
}
else
{
TempData["Added"] = "Invalid Username or password";
return RedirectToAction("LogIn");
}
}
this is my code i get a Null Reference Exception when i entered wrong data .It works fine when i entered correct data .Null Reference Exception is appeared on Session["UserId"].