我无法让RedirectToAction工作

时间:2010-05-14 10:31:07

标签: c# asp.net-mvc

如果用户有效,我有以下操作方法,我正在尝试重定向。但没有任何反应。重定向到动作方法中的断点永远不会被击中。

[AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Login(User user)
    {
        try
            {
                if (ModelState.IsValid)
                {
                    if (userRepository.ValidUser(user))
                    {
                        return RedirectToAction("Index", "Group");
                    }
                    else
                    {
                        return Json("Invalid");
                    }

                }
            }
            catch (Exception)
            {
                return Json("Invalid");
            }


        }

在另一个Controller中,我有以下Action方法,我正在尝试重定向到:

    // HttpVerbs.Post doesn't work either
    [AcceptVerbs(HttpVerbs.Get)]
    public ActionResult Index(int? page)
    {
        const int pageSize = 10;
        IEnumerable<Group> groups = GetGroups();
        var paginatedGroups = new PaginatedList<Group>(groups, page ?? 0, pageSize);
        return View(paginatedGroups);
    }

    private IEnumerable<Group> GetGroups()
    {
        return groupRepository.GetGroups();
    }

我正在做的事情有什么明显的错误吗?有人可以建议我采取不同的方法吗?

1 个答案:

答案 0 :(得分:5)

尝试使用this overload设置routeValues参数:

return RedirectToAction("Index", "Group", new { page = (int?)null });
相关问题