Jeff Mcbride
Jeff Mcbride

Reputation: 453

open an mvc 4 view from javascript in a new window

I'm trying to open a new window (window.open) using javascript in mvc 4. Here's my current code:

                var url = '@Url.Action("Index", "ReportExecution", new {target="_blank"})';
            window.location.href = url;

This doesn't open a new window. It makes the url "ReportExecution/Index?target=_blank". I tried using:

window.open

instead of

window.location.href

but that didn't work. How can this be accomplished?

Upvotes: 0

Views: 14329

Answers (2)

Sudipta Kumar Maiti
Sudipta Kumar Maiti

Reputation: 1709

Your code looks fine but new {target="_blank"}) is redundant.

<script type="text/javascript">
   var url = '@Url.Action("Index", "ReportExecution")';
   window.open(url, '_blank');
</script>

Upvotes: 3

Jeff Mcbride
Jeff Mcbride

Reputation: 453

Ok so this code works for opening a new MVC 4 view in javascript:

window.open('@Url.Action("Index", "ReportExecution")');

Upvotes: 4

Related Questions