Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New window using asp mvc in html form

Tags:

asp.net-mvc

I am building an mvc app for reporting. I have a page that has a form on it which contains multiple dropdownlist to choose some criteria for a report. I then have an input button to create the report. This button call a new view from the same controller. The new view gets the values from the page where the criteria is chosen from parameters and uses that to populate it's own view model. This is all working fine.

I would like to open the reports in a new window. When I look at the controller, all of the parameters that are supposed to be coming from the selection page are null. I assume I will have to pass these in via the querystring to be picked up by the controller. Is there a way that I can get the values of the dropdownlists from within my viewpage to construct the querystring?

Is this a good way to accomplish what I am trying to do? Would I be better of using an ActionLink instead of an input button? does it make any difference?

I hope this all makes sense. Thanks for any thoughts.

like image 929
czuroski Avatar asked Nov 16 '10 13:11

czuroski


1 Answers

Just set a target attribute on your form to _blank and it should open the request in a new page/tab depending on the browser being used.

<% using (Html.BeginForm(myAction, myController, FormMethod.Post, new { target = "_blank" })
   { %>
       <%-- ... --%>
<% } %>
like image 159
Nick Larsen Avatar answered Sep 29 '22 02:09

Nick Larsen