Asp.net mvc 3 如何从操作返回默认视图?
我有两个视图组成相同的登录表单。这些表单调用相同的操作。我想在页面中显示错误。我重定向到indexpage。但当我从loginpage登录时,错误会显示在indexpage中,但我希望从loginpage登录时错误会显示在loginpage中,从index page登录时错误会显示在index page中 我的代码是Asp.net mvc 3 如何从操作返回默认视图?,asp.net-mvc-3,razor,Asp.net Mvc 3,Razor,我有两个视图组成相同的登录表单。这些表单调用相同的操作。我想在页面中显示错误。我重定向到indexpage。但当我从loginpage登录时,错误会显示在indexpage中,但我希望从loginpage登录时错误会显示在loginpage中,从index page登录时错误会显示在index page中 我的代码是 public ActionResult ValidateLogIn(UserLogin users) { if (ModelState.IsValid)
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");
}
我该怎么办?您只需更改最后一行即可返回
登录
视图
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
}