简体   繁体   English

如何通过MVC项目中的Webforms或MVC页面检测我的母版页是否被调用?

[英]How can I detect if my master page is invoked via a Webforms or MVC page in my MVC project?

The project I am working on was a project that was originally WebForms and later migrated to Asp.Net MVC. 我正在开发的项目是一个最初是WebForms并后来迁移到Asp.Net MVC的项目。 3 pages are still using Webforms and it's not worth the effort to rewrite them. 3页仍在使用Webforms,重写它们并不值得。

To prevent having to maintain two separate master pages that look identical I have two master pages, MVC.Master and Webforms.Master . 为了防止不必维护两个独立的母版页,看起来完全相同我有两个母版页, MVC.MasterWebforms.Master Webforms.Master has MVC.Master set as its master page, so that whenever I add a new tool link to my menu it always shows no matter if the user is looking at a Webforms or MVC page. Webforms.MasterMVC.Master设置为它的母版页,所以,每当我添加了一个新的工具链接到我的菜单总是显示,无论用户是否在寻找一个Web表单或MVC页。 The Webforms.Master has nothing but an ajaxToolkit Script manager on it. Webforms.Master有什么,但它的ajaxToolkit脚本经理。

Everything has been working fine until now, where I am adding Telerik support. 到目前为止,一切都运行良好,我正在添加Telerik支持。 The problem is that you cannot use Html helpers in WebForm pages, as you get the exception A ViewMasterPage can be used only with content pages that derive from ViewPage or ViewPage<TModel>. 问题是您无法在WebForm页面中使用Html帮助程序,因为您获得异常A ViewMasterPage can be used only with content pages that derive from ViewPage or ViewPage<TModel>.

Since I do not care if Telerik's script and stylesheet registrars are run for Webform pages, I ideally would like to do something like 由于我不关心Telerik的脚本和样式表注册表是否针对Webform页面运行,我理想情况下想做类似的事情

<% if (!PageIsWebforms) 
   {
       Html.Telerik().....
   }
%>

Unfortunately, I can't think of a good way to successfully determine if the inner page is a WebForms page or not. 不幸的是,我想不出一个成功确定内部页面是否是WebForms页面的好方法。 Does anyone have any ideas how I can accomplish this? 有没有人有任何想法我怎么能做到这一点?

MVC pages inherit something other than System.Web.UI.Page, could you test Page is System.Web.MVC.ViewPage . MVC页面继承了System.Web.UI.Page以外的东西,你可以测试Page is System.Web.MVC.ViewPage吗? You could make that a property to make the markup easier. 您可以使该属性更容易使标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM