I have a MVC project with Razor. There is a view with a partial view on the page. I have a button within the partial view that updates the partial view. This works fine. However, I have another button in the view that I want to open a new view; to "break out" of the original view. Instead, this new view opens where the partial page should be. How can I "break out" of the parent view to open a new view?
This come out of my previous question: How do I get my MVC page to post to the same action in IE and Chrome?
Here are the details. I have a view with a partial view. Clicking on the ButtonB gets some data from the database; everything works fine there.
-------------------------------------------------
| |
| MerchantApplicationSummary.cshtml |
| |
| |
| PartialDiv |
| ----------------------------------- |
| | ApplicationReportPartial.cshtml | |
| | | |
| | [Button B] | |
| ----------------------------------- |
| |
| [Button A] |
-------------------------------------------------
When I click on Button A, I want to open a brand new view:
-------------------------------------------------
| |
| PrintApplication.cshtml |
| |
| |
-------------------------------------------------
Instead, I get the view opening up where the partial view was:
-------------------------------------------------
| |
| MerchantApplicationSummary.cshtml |
| |
| |
| PartialDiv |
| ----------------------------------- |
| | PrintApplication.cshtml | |
| | | |
| ----------------------------------- |
| |
| [Button A] |
| |
-------------------------------------------------
I think this behavior comes from setting the UpdateTargetId to output the partial page inside a div on the original page. I need this so ApplicationReportPartial opens in the correct spot.
MerchantApplicationSummary.cshtml
@using (Ajax.BeginForm(new AjaxOptions { UpdateTargetId = "PartialDiv" }))
{
...
<div id="PartialDiv">
@{
Html.RenderPartial("ApplicationReportPartial");
}
</div>
...
}
Here's the controller which checks if it came from button A or button B:
AdminController.cs
[AuthorizeAdmin]
[HttpPost]
public ActionResult MerchantApplicationSummary(string[] ints, FormCollection form, int? page, string submit)
{
if (ints != null && (submit == "Print Spanish Application(s)" || submit == "Print Application(s)"))
{
return View(@"~/Views/Admin/PrintApplication.cshtml");
}
else
{
...
return PartialView("ApplicationReportPartial", obj_MrntApp);
}
How do I keep it so that the ApplicationReportPartial opens within MerchantApplicationSummary, but so that PrintApplication opens in a new view?
Edit:
Here's the code for button A:
<input id="Submit" name="submit" type="submit" class="btn btn-primary" value="Print Application(s)" />
I actually did have button A as a action link, but I needed it to make it a submit button to pass along certain values. Here's the action again:
public ActionResult MerchantApplicationSummary(string[] ints, FormCollection form, int? page, string submit)
I need the values of ints when I click on button A; ints is an array of the IDs of checkboxes checked on the page. If I use an action link, how would I pass along those values to the action? -- I did some research and it look like this is not possible (see http://forums.asp.net/t/1470988.aspx?HTML+ActionLink+to+post) so this brings me back to my original question of how to "break out" of the parent view.