共享MVC和WebForms的之间的主 - 处理的<形式为GT; [英] Sharing a master between MVC and WebForms - dealing with the <form>

查看:98
本文介绍了共享MVC和WebForms的之间的主 - 处理的<形式为GT;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个大的遗留应用程序,我们要开始使用MVC的新功能。

We have a large legacy application where we want to start using MVC for new functionality.

要做到这一点,我们添加了自定义的路由,例如:

To do this we added custom routing, for instance:

routes.IgnoreRoute( "{*allaspx}", new { allaspx = @".*\.as[pmh]x(/.*)?" } );

和我们想的老WebForms和新的MVC页面之间共享的母版页。

And we want to share the master page between the old WebForms and the new MVC pages.

这似乎很简单 - 改变了主从 ViewMasterPage 继承,它可以被用来作为主为MVC页太

This seems simple enough - changed the master to inherit from ViewMasterPage and it can be used as the master for MVC pages too.

问题是HTML <形式的方式>

母版页有一个<形式为GT; 在它里面的顶部和3含量的面板,这就好比是如何的WebForms标签。在控制将代替师傅的形式在页面点回来了,这似乎是一个很难codeD的行为。

The master page has a <form> tag at the top and 3 content panels inside it, which is how WebForms like it. The Page control overrides the master's form to point back at the page, and this appears to be a hardcoded behaviour.

这三个内容面板拥有的WebForms控件,因此页面级&LT;形式为GT; 标记需要在外面他们涵盖所有三种。事情是这样的:

All three content panels have WebForms controls, so the page level <form> tag needs to be outside them to cover all three. Something like this:

<form id="form1" runat="server">
    ...
    <asp:contentplaceholder id="content1" runat="server" />
    ...
    <asp:contentplaceholder id="content2" runat="server" />
    ... //etc
</form>

不过,对于MVC我们希望有使用 Html.BeginForm 助手的意见,里面的形式。 HTML不会让你窝形式。 MVC模式需要的意见,回发到不同的动作(例如一个细节的观点可能会发送回一个编辑操作)。

However, for MVC we want to have forms inside the views using the Html.BeginForm helper. HTML doesn't let you nest forms. MVC pattern needs the views to post back to different actions (for instance a "details" view might post back to an "edit" action).

有谁知道解决这个好办法?

Does anyone know a good way around this?

推荐答案

我们共享Web Forms和MVC之间的主网页,其中不具有&LT;形式&GT; 。您可以为这反过来又用你的根母版页网页形式的中间母版页,但增加了&LT;形式为GT; 。主页的层次结构是用于这些构建非常有用的。

We share a master page between web forms and MVC which doesn't have the <form>. You can create an intermediate master page for web forms which in turn uses your root master page, but adds the <form>. The hierarchical structure of master pages is very useful for these constructs.

这篇关于共享MVC和WebForms的之间的主 - 处理的&lt;形式为GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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