Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 3 如何从操作返回默认视图?_Asp.net Mvc 3_Razor - Fatal编程技术网

Asp.net mvc 3 如何从操作返回默认视图?

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)

我有两个视图组成相同的登录表单。这些表单调用相同的操作。我想在页面中显示错误。我重定向到indexpage。但当我从loginpage登录时,错误会显示在indexpage中,但我希望从loginpage登录时错误会显示在loginpage中,从index page登录时错误会显示在index page中

我的代码是

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
    }