Open New tab from code behind in MVC

Go To


I need to open another site in new tab from code behind in MVC.

return Redirect("Url"); is used to open the another site within the same tab.

2012-04-04 07:03
by yogee


It doesn't really seem practical for the users, because after authenticating in the second tab, they have to refresh the first tab to see the effects.

The ReturnUrl property of FormsAuthentication seems to do what you want. When the user needs to log in, they are redirected to the login page, and after signing in they are redirected back.

If you are making extensive use of javascript and ajax, and want to keep the javascript variables of the current page but need to log in to do the ajax calls, there might be another solution. If the response of your ajax call is the unauthenticated header, open a lightbox or something like that with a username and password field. Use ajax post to the AccountController to sign in the user again. This way, the user is authenticated again, but you keep the javascript variables.

2012-04-04 07:30
by Jesse van Assen


This can be done using javascript only. Try this.

<% Response.Write '<script type="text/javascript">; </script>' %>

Hope it works.

2012-04-05 06:37
by Hemesh Singh


if you call action from form and use input type of submit you can try <input type="submit" formtarget="_blank" /> if you use link <a> or AjaxCall you can try <a target="_blank"></a> or in ajax helper set property @target="_blank"

here is my code cshtml

 @using (Html.BeginForm("PersonsReport", "Reports"))
            <br />
            <div style="text-align: center;">
                <input type="submit" formtarget="_blank" class="btn btn-primary" value="GetReport" style="width:100%;" />
            <br />


 public ActionResult PersonsReport()
        return Redirect("/PersonsReport.aspx");

2014-09-03 09:45
by Alexandr