Tom Anderson
Tom Anderson

Reputation: 10827

How to switch master page depending on IFrame

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).

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

Upvotes: 1

Views: 1345

Answers (2)

Eran Kampf
Eran Kampf

Reputation: 8986

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

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

Upvotes: 2

Craig Stuntz
Craig Stuntz

Reputation: 126547

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.

Upvotes: 0

Related Questions