Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 592
ProfK Avatar asked Feb 15 '23 15:02

ProfK


1 Answers

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

like image 83
Mohammed Dawood Ansari Avatar answered Feb 22 '23 02:02

Mohammed Dawood Ansari