如何让我的MVC页面张贴在IE和Chrome相同的动作? [英] How do I get my MVC page to post to the same action in IE and Chrome?

查看:140
本文介绍了如何让我的MVC页面张贴在IE和Chrome相同的动作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MVC /剃刀站点设置,其中不同的操作取决于用户是否使用Chrome 42或IE 11的按钮在局部视图调用。在Chrome中,点击按钮可以在局部视图BeginForm标签定义的动作。在IE浏览器,点击按钮将在母公司的BeginForm标签定义的动作。为什么会出现这种情况,我怎么能控制什么样的行动被称为IE?

I have a MVC/Razor site setup where a different action is called depending on whether the user is using Chrome 42 or IE 11. The button is in a partial view. In Chrome, clicking the button takes you to the action defined in the partial views BeginForm tag. In IE, clicking the button takes you to the action defined in the parent's BeginForm tag. Why would this happen and how can I control what action is called in IE?

在简单地说,我有


  • 视图,MerchantApplicationSummary,以局部视图,PrintApplication

  • PrintApplication有一个按钮,要求在IE PrintApplication()在Chrome,但MerchantApplicationSummary()

下面是一些code例子:

Here are some code examples:

我有一个局部视图的视图。

I have a view with a partial view.

MerchantApplicationSummary.cshtml

MerchantApplicationSummary.cshtml

@using (Ajax.BeginForm(new AjaxOptions { UpdateTargetId = "PartialDiv" }))
{
...
<div id="PartialDiv">
@{
   Html.RenderPartial("PrintApplication");
 }
</div>
...
}

-------------------------------------------------
|                                               |
| MerchantApplicationSummary.cshtml             |
|                                               |
|    -----------------------------------        |
|    | PrintApplication.cshtml         |        |
|    |                                 |        |
|    -----------------------------------        |
|                                               |
-------------------------------------------------

这部分观点有一个按钮,它调用一个动作

This partial view has a button which calls an action

PrintApplication.cshtml

PrintApplication.cshtml

    @using (Html.BeginForm("PrintApplications", "Admin", FormMethod.Post, new { @id = "PrintApplications", @class = "form-horizontal ", @commandname = "ModelContract", @target = "_blank" }))
    {
      <input id="btnPrintApplications" type="submit" class="btn btn-primary" value="PrintApplications" name="PrintApplications" />
    }

这是哪里出现问题。在Chrome中,PrintApplications被调用。这是正确的行为。然而,在IE浏览器,MerchantApplicationSummary被调用。我最初的想法是,这是因为这两个BeginForm语句,但我还没有找到一种方法来改变他们得到它的工作。

This is where the problem occurs. In Chrome, PrintApplications is called. This is the correct behavior. However, in IE, MerchantApplicationSummary is called. My initial thought was that it was because of the two BeginForm statements, but I haven't found a way to change them to get it to work.

AdminController.cs

AdminController.cs

    [AuthorizeAdmin]
    [HttpPost]
    public ActionResult MerchantApplicationSummary(string[] ints, FormCollection form, int? page, string submit)
    {
      ...
    }

    [AuthorizeAdmin]
    [HttpPost]
    public ActionResult PrintApplications(ModelApplication currentApplication)
    {
    }

基本上我想点击btnPrintApplications并使用它调用PrintApplications行动,Chrome和IE浏览器。

Basically I want to click on btnPrintApplications and have it call the PrintApplications action in both Chrome and IE.

请让我知道如果我可以给任何进一步的细节。谢谢!

Please let me know if I can give any further details. Thank you!

推荐答案

表格内的表格无效HTML。浏览器如何最终处理它,那么,完全是基于个人的浏览器是如何呈现这些页面并处理纠错,两件事情你的的控制。

A form within a form is invalid HTML. How the browser ends up handling it, then, is entirely based on how the individual browser renders the page and handles error correction, two things you have zero control over.

如果您希望您的应用程序行为一致,那么你需要使用有效的HTML。换句话说,找到另一种方式做你想要做的比其他在另一个具有一种形式的东西。

If you want your application to behave consistently, then you need to use valid HTML. In other words, find another way to do what you're trying to do other than having a one form within another.

这篇关于如何让我的MVC页面张贴在IE和Chrome相同的动作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆