如何根据IFrame切换母版页

时间:2021-12-17 21:13:20

I want to use an IFrame in my ASP.Net MVC application, yet I want to retain the layout when the internal pages are navigated via direct access (Search Engine).

我想在我的ASP.Net MVC应用程序中使用IFrame,但我希望在通过直接访问(搜索引擎)导航内部页面时保留布局。

How would I switch the master page based on whether the View was in an IFrame, or a top level window?

如何根据View是在IFrame还是*窗口中切换母版页?

2 个解决方案

#1


The ViewResult you return in your controller Action has a MasterName property. Have your controller action receive a parameter that tells it whether you're in an IFrame or not and then you can do

您在控制器中返回的ViewResult Action具有MasterName属性。让您的控制器操作接收一个参数,告诉它您是否在IFrame中然后就可以了

if (isInIFrame)
{
    ViewResult result = View();
    result.MasterName = "IFrameMaster";
    return result;
}

#2


One way:

Put the content in a user control. Write a lightweight view which wraps the user control for the IFrame version, and another for the top-level version.

将内容放在用户控件中。编写一个轻量级视图,用于包装IFrame版本的用户控件,另一个用于*版本。

#1


The ViewResult you return in your controller Action has a MasterName property. Have your controller action receive a parameter that tells it whether you're in an IFrame or not and then you can do

您在控制器中返回的ViewResult Action具有MasterName属性。让您的控制器操作接收一个参数,告诉它您是否在IFrame中然后就可以了

if (isInIFrame)
{
    ViewResult result = View();
    result.MasterName = "IFrameMaster";
    return result;
}

#2


One way:

Put the content in a user control. Write a lightweight view which wraps the user control for the IFrame version, and another for the top-level version.

将内容放在用户控件中。编写一个轻量级视图,用于包装IFrame版本的用户控件,另一个用于*版本。