是否有可能共享MVC和Web表单之间的母版? [英] Is it possible to share a masterpage between MVC and webforms?

查看:175
本文介绍了是否有可能共享MVC和Web表单之间的母版?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我加入MVC到有许多遗留Web窗体页的项目。这工作得很好。不过,我现在对MVC和的web表单一个单独的母版。这两个母版页产生基本相同的输出。我真的很想杀的webforms之一,只需使用MVC母版页用我所有的网页,并保持干燥。

I am adding MVC to a project that has MANY legacy webform pages. This works fine. However, I currently have a separate masterpage for MVC and for the webforms. The two master pages produce essentially identical output. I'd really like to kill the webforms one and just use the MVC master page with all my pages and stay DRY.

由于不是DRY已经咬伤了我几次,当我忘了同时改变。

Not being DRY has already bitten me a couple times when I forgot to change both.

我试着做了明显的方式,只是指着MVC母版的Web窗体内容页的母版属性。这将引发一个错误,说了MVC的主人只与MVC视图的工作。

I tried doing the obvious way and just pointing the webform content page's MasterPage attribute at the MVC masterpage. This throws an error saying the MVC masters only work with MVC views.

这似乎将是混合MVC Web窗体和项目pretty通病。我的MVC主人是不是做与ViewData的东西,所以我看不出有任何理由web表单不能使用它们。

This seems like it would be a pretty common problem with mixed MVC and webform projects. My MVC master isn't doing anything with ViewData, so I don't see any reason the webforms couldn't use them.

推荐答案

您绝对可以共享相同的母版页。你的MVC母版页必须简单地指向的WebForms通过它的MasterPageFile属性母版。这适用于您的WebForms母版风格,以你的MVC母版。

You can absolutely share the same master page. Your MVC master page must simply point to the WebForms masterpage via its MasterPageFile attribute. This applies your WebForms MasterPage styles to your MVC MasterPage.

我在生产中使用此设置。

I am using this setup in production.

在我的MVC母版页的声明,在Web窗体指向母版页:

The declaration on my MVC Master Page, pointing at the Web Forms Master Page:

<%@ Master Language="C#" MasterPageFile="~/MasterPage/Site.Master"
AutoEventWireup="true" Inherits="System.Web.Mvc.ViewMasterPage" %>

工程就像一个魅力。

Works like a charm.

这篇关于是否有可能共享MVC和Web表单之间的母版?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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