ASP.NET MVC 3 - redirect to another action

前端 未结 5 1286
攒了一身酷
攒了一身酷 2020-12-02 18:20

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()
    {
          


        
相关标签:
5条回答
  • 2020-12-02 18:30

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

    return RedirectToAction("ActionName", "ControllerName");
    
    0 讨论(0)
  • 2020-12-02 18:35

    Should Return ActionResult, instead of Void

    0 讨论(0)
  • 2020-12-02 18:37

    Your method needs to return a ActionResult type:

    public ActionResult Index()
    {
        //All we want to do is redirect to the class selection page
        return RedirectToAction("SelectClasses", "Registration");
    }
    
    0 讨论(0)
  • 2020-12-02 18:37

    You will need to return the result of RedirectToAction.

    0 讨论(0)
  • 2020-12-02 18:42
    return RedirectToAction("ActionName", "ControllerName");
    
    0 讨论(0)
提交回复
热议问题