ASPX Page Response.Redirect to MVC View

断了今生、忘了曾经 提交于 2019-12-01 00:31:52

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).

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.

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

Try this :

Response.Redirect(Url.Action("Index", "Home"));

Try This

Response.Redirect("~/Home/Index");
Hemang Padia
var page = HttpContext.Current.Handler as Page;
Response.Redirect(page.GetRouteUrl("Default",
    new { Controller = "Nameofcontroller", Action = "Nameofaction" }), false);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!