views:

766

answers:

2

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?

A: 

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.

Craig Stuntz
+1  A: 

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;
}
Eran Kampf
great reply, thanks.
Tom Anderson