2

Is there any way to open a new window if the Submit Button is inside @using Html.BeginForm? I tried the following but it doesn't work?

@using (Html.BeginForm("SetCol", "Document", FormMethod.Post, new {target="_blank"})){
<div class="modal-body" data-height-relative="20">
.
.
.
</div>
    <div class="modal-footer">
        <div class="pull-right">
            <input type="submit" value="Senden" class="btn btn-primary"/>
            <a href="@ViewData["closeUrl"]" class="btn btn-primary" @(ViewData["closeUrl"] == "#" ? "data-dismiss=modal" : "")>@Translations.Close</a>
        </div>
    </div>
}

The output is a PDF File:

<html>
  <body marginwidth="0" marginheight="0" style="background-color:  rgb(38,38,38)">
 <embed width="100%" height="100%" name="plugin" src="http://localhost:54906/Document/SetCol?id=108" type="application/pdf">
  </body>
</html>
user576914
  • 199
  • 1
  • 8
  • 22
  • possible duplicate of [Javascript Post on Form Submit open a new window](http://stackoverflow.com/questions/178964/javascript-post-on-form-submit-open-a-new-window) – CodeCaster Apr 03 '15 at 09:46
  • You have the wrong target, you need `_blank` instead of `_self`. But please don't do this, it's horrible user experience. – CodeCaster Apr 03 '15 at 09:47
  • I tried blank_ but I still get the result in the same window. Why is horrible and what is the alternative? – user576914 Apr 03 '15 at 09:49
  • Why would you want a form submit to open a new window? Anyway show the generated HTML. – CodeCaster Apr 03 '15 at 09:51
  • The result is a pdf File(it can also be XPS,HTML etc) and I want it in a new window. Currently the generated PDF opens in the same window – user576914 Apr 03 '15 at 09:54
  • That sounds reasonable. Still, the `target="_blank"` should work. Update your question with the HTML this code generates. – CodeCaster Apr 03 '15 at 09:54

1 Answers1

6

Below line works for me with your code. May be something related to your action method.

@using (Html.BeginForm("About", "Home", FormMethod.Post, new { target = "_blank" })) 

As you mentioned in your comment, that this method returns a PDF file, you can use window.open like:

window.open("../Document/SetCol", "_blank");

or

window.open("@Url.Action("LoadReport", "ExportReport")" + link, "_blank");

You will have to define a click event handler obviously.

SBirthare
  • 5,117
  • 4
  • 34
  • 59