Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6017821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:11:04+00:00 2026-05-23T03:11:04+00:00

In Razor, when loading a partial view, it is possible to just specify the

  • 0

In Razor, when loading a partial view, it is possible to just specify the partial view name, and the Razor view engine will search the RazorViewEngine.PartialViewLocationFormats:

@Html.RenderPartial("_PartialView", Model);

will actually search the locations specified in PartialViewLocationFormats in the view engine, such as for example

~/Views/Home/_PartialView.cshtml
~/Views/Shared/_PartialView.cshtml

However, when specifying the Layout, I seem to be forced to specify a specific path to the layout:

@Layout = "~/Views/Shared/MyLayout.cshtml";

What I would like to do would be to specify the layout just by name, and have the the actual layout be found by searching a list of common locations:

@Layout = "MyLayout";

…but I can’t find any facilities to do so. Since I could not find any documentation regarding this, I tried playing with setting RazorViewEngine.MasterLocationFormats, but this property is not used when locating layouts.

Does anybody know how to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T03:11:05+00:00Added an answer on May 23, 2026 at 3:11 am

    Recently I was struggling on a similar issue where, in a themed application that uses a custom ViewEngine to search theme’s location first for views, I was trying to override some master files. One way to force the location of the layout to go through the ViewEngine’s FindView is to specify the name of the master view in a controller action when returning:

    return View("myView", "myViewMaster");
    

    However, if “myViewMaster” also has a layout (nested layouts), this method doesn’t work for the nested layout. My best solution so far is to call the view engine directly in the view:

    @{
        Layout = (ViewEngines.Engines.FindView(this.ViewContext.Controller.ControllerContext, "myViewMaster", "").View as RazorView).ViewPath;
    }
    

    This works but could certainly be encapsulated in a extension method to avoid repetition and abstract the code.

    Hope it helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The Razor view engine automatically differentiates between Server code and Html Code For example
Using the razor view engine, I have some code like the following: @Html.TextAreaFor(model =>
Is there any documentation on how to use the Razor view engine using ASP.NET
I am working with razor view engine in asp.net mvc3. Now, I need an
The Razor view engine in ASP.NET MVC supports @helper to define little helper methods.
Using MVC3 and Razor View engine, I created a VB.NET web application in VS
I'm using the Razor view engine with MVC3 RC1 and Razor, and running through
i created a Razor partial view in visual studio 2010 it added it as
I am using @Darin Dimitrov's method explained in Loading a partial view in jquery.dialog
I have a need to learn MVC 3 with the Razor view engine and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.