Controller-
public ActionResult Login(Customer d)
{
using (CustomerDataEntities oe = new CustomerDataEntities())
{
var user = oe.Customers.FirstOrDefault(a => a.UserName.Equals(d.UserName) && a.Password.Equals(d.Password));
if (user == null)
{
TempData["ErrorMessage"] = "Invalid user name or password."
return RedirectToAction("Login", "Home");
}
else
{
return RedirectToAction("Index", "Home");
}
}
}
View- Place this code wherever you want to display the error message
@{
if(TempData["ErrorMessage"] != null)
{
<div id="errorMsg" style="border: solid 1px red; padding: 50px 10px; color:red">
@TempData["ErrorMessage"]
</div>
}
}
-KR