ASP。NET MVC 3 -重定向到另一个操作

时间:2022-03-11 18:17:43

I want to redirect the Index action of the Home controller to another controller's action and nothing else. My code is thus:

我想将主控制器的索引操作重定向到另一个控制器的操作。我的代码是:

    public void Index()
    {
        //All we want to do is redirect to the class selection page
        RedirectToAction("SelectClasses", "Registration");
    }

Right now, this just loads a 0 kB blank page and does nothing. I have a feeling it has something to do with that void return type, but I don't know what else to change it to. What's the issue here?

现在,它只加载一个0 kB的空白页,什么都不做。我有一种感觉它和那个空返回类型有关,但是我不知道还有什么可以改变它。这里的问题是什么?

5 个解决方案

#1


126  

Your method needs to return a ActionResult type:

您的方法需要返回一个ActionResult类型:

public ActionResult Index()
{
    //All we want to do is redirect to the class selection page
    return RedirectToAction("SelectClasses", "Registration");
}

#2


18  

You will need to return the result of RedirectToAction.

您将需要返回RedirectToAction的结果。

#3


14  

Should Return ActionResult, instead of Void

应该返回ActionResult而不是Void

#4


5  

You have to write this code instead of return View(); :

您必须编写此代码,而不是return View();:

return RedirectToAction("ActionName", "ControllerName");

#5


0  

return RedirectToAction("ActionName", "ControllerName");

#1


126  

Your method needs to return a ActionResult type:

您的方法需要返回一个ActionResult类型:

public ActionResult Index()
{
    //All we want to do is redirect to the class selection page
    return RedirectToAction("SelectClasses", "Registration");
}

#2


18  

You will need to return the result of RedirectToAction.

您将需要返回RedirectToAction的结果。

#3


14  

Should Return ActionResult, instead of Void

应该返回ActionResult而不是Void

#4


5  

You have to write this code instead of return View(); :

您必须编写此代码,而不是return View();:

return RedirectToAction("ActionName", "ControllerName");

#5


0  

return RedirectToAction("ActionName", "ControllerName");