开发者

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

开发者 https://www.devze.com 2023-03-04 17:35 出处:网络
The project I am working on was a project that was originally WebForms and later migrated to Asp.Net MVC.3 pages are still using Webforms and it\'s not worth the effort to rewrite them.

The project I am working on was a project that was originally WebForms and later migrated to Asp.Net MVC. 3 pages are still using Webforms and it's not worth the effort to rewrite them.

To prevent having to maintain two separate master pages that look identical I have two master pages, MVC.Master and Webforms.Master. Webforms.M开发者_开发知识库aster 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. The Webforms.Master has nothing but an ajaxToolkit Script manager on it.

Everything has been working fine until now, where I am adding Telerik support. 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>.

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

<% 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. 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. You could make that a property to make the markup easier.

0

精彩评论

暂无评论...
验证码 换一张
取 消