问题
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