在MVC /剃须刀,你怎么能打开一个新视图,而不是作为一个局部视图? [英] In MVC/Razor, how can you open a new view instead of as a partial view?
问题描述
我有一个剃刀MVC项目。没有与页面上的局部视图的视图。我有一个更新的局部视图局部视图中的一个按钮。这工作得很好。不过,我有,我想打开一个新的观点认为另一个按钮; 打破了原来的看法。相反,这种新的视图中打开,其中的部分页面应该的。我怎样才能突围父视图中打开一个新的看法?
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?
这走出我的previous问题:<一href=\"http://stackoverflow.com/questions/30263628/how-do-i-get-my-mvc-page-to-post-to-the-same-action-in-ie-and-chrome\">How让我的MVC页面张贴在IE和Chrome一样的动作?
This come out of my previous question: How do I get my MVC page to post to the same action in IE and Chrome?
下面是详细内容。我有一个局部视图的视图。点击ButtonB从数据库获取一些数据;一切工作正常那里。
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] |
-------------------------------------------------
当我点击按钮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] |
| |
-------------------------------------------------
我觉得这种行为来自于原来的页面上UpdateTargetId的部分页面设置为输出一个div里面。我需要这让ApplicationReportPartial在正确的位置打开。
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
MerchantApplicationSummary.cshtml
@using (Ajax.BeginForm(new AjaxOptions { UpdateTargetId = "PartialDiv" }))
{
...
<div id="PartialDiv">
@{
Html.RenderPartial("ApplicationReportPartial");
}
</div>
...
}
下面是它检查是否从按钮A或B按钮来控制器:
Here's the controller which checks if it came from button A or button B:
AdminController.cs
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);
}
我如何保持这样的ApplicationReportPartial内MerchantApplicationSummary打开,但这样PrintApplication在新视图中打开?
How do I keep it so that the ApplicationReportPartial opens within MerchantApplicationSummary, but so that PrintApplication opens in a new view?
编辑:
这里的code的按钮答:
Here's the code for button A:
<input id="Submit" name="submit" type="submit" class="btn btn-primary" value="Print Application(s)" />
其实我确实有按钮A作为操作链接,但我需要它,使之一个提交按钮沿着特定的值传递。下面是再次行动:
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)
我需要整型值当我点击按钮A;整数是复选框页上选中的ID的数组。如果我使用一个操作环节,我将如何沿着这些值的动作过关? - 我做了一些研究,它看起来像这样是不可能的(见的 http://forums.asp.net/t/1470988.aspx?HTML+ActionLink+to+post ),所以这让我回到我原来的父视图如何突围的问题。
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.
推荐答案
我通过以下操作解决了这个问题:
- 在父视图,我用BeginForm代替Ajax.BeginForm和离开的UpdateTargetId分配。
- 在控制器中,返回的局部视图,而不是一个局部视图视图
I solved the problem by doing the following: - In the parent view, I used BeginForm instead of Ajax.BeginForm and left off the UpdateTargetId assignment. - In the controller, returned a View for the partial view instead of a partial view.
MerchantApplicationSummary.cshtml
MerchantApplicationSummary.cshtml
@using (Html.BeginForm("MerchantApplicationSummary", "Admin"))
{
...
<div id="PartialDiv">
@{
Html.RenderPartial("ApplicationReportPartial");
}
</div>
...
<input id="Submit" name="submit" type="submit" class="btn btn-primary" value="Print Application(s)" />
}
AdminController.cs
AdminController.cs
[AuthorizeAdmin]
[HttpPost]
public ActionResult MerchantApplicationSummary(string[] ints, FormCollection form, int? page, string submit, string PrintApplications)
{
if (ints != null && (submit == "Print Spanish Application(s)" || submit == "Print Application(s)"))
{
...
return View(@"~/Views/Admin/PrintApplication.cshtml");
}
else
{
...
return View(obj_MrntApp);
}
}
这篇关于在MVC /剃须刀,你怎么能打开一个新视图,而不是作为一个局部视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!