How to Redirect From WebForms to a MVC View?

这一生的挚爱 提交于 2019-12-08 04:55:01

问题


I use an ASP.net WebForm in a MVC application.
I need to redirect to a MVC View or to an ActionResult method in a Controller from WebForm Button Click Event.
Is there a way to do this?

public ActionResult Index()
{                                                             
    //Method in MVC Controller                                                                 
    //Rest of the code                                                    
}

Tried as below to redirect to a method in Controller:

protected void btnCreate_Click(object sender, EventArgs e)
{                    
    Response.Redirect("~/BreakdownReports/Index",false);
    Context.ApplicationInstance.CompleteRequest();                        
}

回答1:


try it I redirected from .aspx to MVC controller page

 protected void btnCreate_Click(object sender, EventArgs e)
        {                    
        var page = HttpContext.Current.Handler as Page;
         Response.Redirect(page.GetRouteUrl("Set hereDefaultroute", 
          new { Controller="BreakdownReports", Action="Index"}), false);               
        }



回答2:


Try:

Response.Redirect("BreakdownReports/Index");

also

Response.Redirect("./BreakdownReports/Index");


来源:https://stackoverflow.com/questions/56149217/how-to-redirect-from-webforms-to-a-mvc-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!