ASPX Page Response.Redirect to MVC View

前端 未结 6 532
清酒与你
清酒与你 2021-01-07 04:20

Is it possible to Response.Redirect in aspx that returns a view from MVC?

I have an login.aspx page that i need upon successful login to redirect to a view in ~/Vie

相关标签:
6条回答
  • 2021-01-07 04:49
    var page = HttpContext.Current.Handler as Page;
    Response.Redirect(page.GetRouteUrl("Default",
        new { Controller = "Nameofcontroller", Action = "Nameofaction" }), false);
    
    0 讨论(0)
  • 2021-01-07 04:57

    Try This

    Response.Redirect("~/Home/Index");
    
    0 讨论(0)
  • 2021-01-07 05:00

    Here is how I redirect from .aspx to an MVC view:

    var page = HttpContext.Current.Handler as Page;
    Response.Redirect(page.GetRouteUrl("yourRouteNameOrDefault", 
        new { Controller="Home", Action="Index"}), false);
    

    Keeps you from hard-coding in the actual path and instead uses your routing and also allows you to build in routeParameters.

    0 讨论(0)
  • 2021-01-07 05:00

    try this:

    return RedirectToAction("Index");
    

    assuming that this is in the same controller , if not:

    return RedirectToAction("Index", "Home");
    

    in the MVC framework you don't redirect to views directly , you redirect to Actions, then there me be some logic in there , and based on the logic from the Action it will choose a view and fill out a view model if necessary

    0 讨论(0)
  • Try this :

    Response.Redirect(Url.Action("Index", "Home"));
    
    0 讨论(0)
  • 2021-01-07 05:11

    How about Response.Redirect("/Home/Index"); - that is of course presuming that you have a HomeController with an Index action that returns the view you're looking for (by convention it's going to be a view having the same name as the action, unless you specify otherwise).

    0 讨论(0)
提交回复
热议问题