重定向到操作在MVC中不起作用

时间:2015-02-09 16:42:23

标签: asp.net asp.net-mvc asp.net-mvc-4 redirect

我有一个控制器CMS,你可以在这里看到:

  [HttpGet]
        public ActionResult Login(string returnUrl)
        {



            return View(); // show the login page
        }
        UserRepository ObjUserRepository = new UserRepository();
        [HttpPost]
        public ActionResult Login(DomainClass.User loginInfo, string returnUrl)
        {


            if (ObjUserRepository.FindBy(i => i.Email == loginInfo.Email & i.Password == loginInfo.Password).Any())
            {
                DomainClass.User objUser = ObjUserRepository.FindBy(i => i.Email == loginInfo.Email & i.Password == loginInfo.Password).FirstOrDefault();

                FormsAuthentication.SetAuthCookie(loginInfo.Email, false);
                if (shouldRedirect(returnUrl))
                {
                    return Redirect(returnUrl);
                }

                if (objUser.Pemission == "professor")
                {
                    return RedirectToAction("Index", "Home", new { Area = "Teacher" });
                }


            }


        return View(loginInfo);
    }

我调用此网址../cms/login并显示我的login视图,我输入usernamepassword,执行此部分代码:

  if (objUser.Pemission == "professor")
                {
                    return RedirectToAction("Index", "Home", new { Area = "Teacher" });
                }

但是mvc再次将我重定向到了Login页面,但它应该将我重定向到/teacher/home/index

1 个答案:

答案 0 :(得分:1)

更改

return RedirectToAction("Index", "Home", new { Area = "Teacher" });

return RedirectToAction("Index", "Home", new { area = "Teacher" });

area参数是小写。