How to open cshtml file in new tab from controller's method?

asp.net-mvc-3

Solution

If you are getting to the action from the first page via an Html.ActionLink you can do this:

Html.ActionLink("Open Invoice", "ActionName","ControllerName", new { id = Model.InvoiceID }, new { target = "_blank" });

Specifying target = "_blank" will open in the new tab

Update

Since you are posting the model to the controller (I was hoping RedirectToAction could help open a new window/tab but that doesn't look to be the case)

My spidy sense is tingling on the flow you have tho... This is just me but I would do something a little different.. such as

- Post the model to the controller

- Save the data that generates the invoice

- Return the InvoiceID to the action

- Add the InvoiceID to the model

- Send the model back to the view

- Inform the user that

- the invoice was generated and show a link - like above - that allows the user to open the invoice OR

- this provides the perfect clean solution to show model errors if there were any

Your view could have a piece of razor code that did that:

@{
    if(Model.InvoiceID != null && Model.InvoiceID !=0) {
        @Html.ActionLink("Open Invoice", "ActionName","ControllerName", new { id = Model.InvoiceID }, new { target = "_blank" });
    } 
}

Problem

I'm working on a Nopcommerce, and need to generate Invoice (custom made not as what they already provide, because it just doesn't solve our purpose). We need to generate Invoice in new tab(using another cshtml file) using Controller's method also I'm passing model data on view. ``` <tr> <td class="adminTitle"> @Html.NopLabelFor(model => model.ProbableDeliveryDate): </td> <td class="adminData"> @Html.EditorFor(model=>model.ProbableDeliveryDate) </td> </tr> <tr> <td> @if(Model.CanGenrateInvoice) { <input type="submit" name="generateinvoice" value="@T("Admin.Orders.Fields.generateinvoice")" id="generateinvoice" class="adminButton" /> } </td> </tr> ``` I've to post data to get value of probableDeliveryDate to controller method and after that want to open view in new tab. How can i do this?

Original source