我有两个视图,它们包含相同的登录表单。表单调用相同的操作。我想在页面中显示错误。我重定向到indexpage。但是当我从登录页面登录错误在indexpage中显示但是我希望从登录页面登录时在登录页面中显示错误,并且在从索引页面登录时在索引页面中显示错误
我的代码是
public ActionResult ValidateLogIn(UserLogin users)
{
if (ModelState.IsValid)
{
var result = _accountUserService.GetAccountUserByEmailId(users.Email);
if (result != null)
{
if (result.Password == users.Password && result.Active)
{
Session.Add("Username", result.Email);
ViewBag.email = users.Email;
return View("Index");
//return full form registration;
}
ViewBag.UError = NcMessage.NotAcitvated;
}
else
{
ViewBag.UError = NcMessage.UsernameNotFound;
}
}
return View("Index");
}
我该怎么办?
答案 0 :(得分:0)
您只需更改最后一行即可返回login
视图
public ActionResult ValidateLogIn(UserLogin users)
{
if (ModelState.IsValid)
{
var result = _accountUserService.GetAccountUserByEmailId(users.Email);
if (result != null)
{
if (result.Password == users.Password && result.Active)
{
Session.Add("Username", result.Email);
ViewBag.email = users.Email;
return View("Index");
//return full form registration;
}
ViewBag.UError = NcMessage.NotAcitvated;
}
else
{
ViewBag.UError = NcMessage.UsernameNotFound;
}
}
return View("Login");
// Return to Login page as Authentication is unsuccessful or ModelState is Invalid
}