Search code examples
asp.net-mvcasp.net-mvc-4crystal-reportswebformscrystal-reports-2010

What must I do to redirect to a Web Form from an MVC controller?


I have this line in my controller:

Response.Redirect("~/WebForms/ReportViewer.aspx");

Then this simple test code in Page_Load of "ReportViewer.aspx":

protected void Page_Load(object sender, EventArgs e)
{
    Response.Write("Hello");
    return;
}

This code does not even execute, i.e. Page_Load does not execute. I suppose there is something I'm supposed to do before redirecting to a web form, but have no idea what it is. I have seen ample sample code that just plainly calls Redirect.

My web form does have a Crystal Reports viewer on it, which may have something to do with the situation:

<body>
    <form id="form" runat="server">
        <CR:CrystalReportViewer ID="CrystalViewer" runat="server" AutoDataBind="true" />
    </form>
</body>

Solution

  • return Redirect("~/Webform.aspx");
    

    is perfect and its return type is RedirectResult and it works awesome, I have tested it.

    My Action look like this

        public ActionResult Print()
        {
            return Redirect("~/Webform2.aspx");
        }
    

    Thanks to @Andrey Gubal