How can I redirect to a URL?

前端 未结 5 2121
名媛妹妹
名媛妹妹 2020-12-15 16:09

How can I redirect the viewer to a URL?

I noticed that someone asked How to redirect to another webpage in JavaScript/jQuery?, but I\'m not exactly sure where this

5条回答
  •  星月不相逢
    2020-12-15 16:50

    Inside your controller call return RedirectToAction().

    public ActionResult MyAction() {
    
        return RedirectToAction("Index", "Home");
    }
    

    or, it you use T4MVC (and you should ;-))

    public ActionResult MyAction() {
    
        return RedirectToAction(MVC.Home.Index());
    }
    

    Do not put the if statement in the view - that's not the MVC way. It is the responsibility of the controller to decide whether to redirect to a different view.

提交回复
热议问题