1

If I understand correctly it is intended to specify which locations are searched in order to locate the master _Layout.cshtml file.

However my _ViewStart.cshtml file requires a full path, e.g. ~/Views/Shared/_Layout.cshtml. This means that any location(s) specified in MasterLocationFormats are totally ignored.

My Questions Are:

  • Why bother including MasterLocationForamts[] in the first place?
  • Is there another use for MasterLocationFormats[] that I'm missing?
  • Is there a way to make _ViewStart.cshtml search in the locations specified in MasterLocationFormats[]?

I have tried using a relative path like _Layout.cshtml in _ViewStart.cshtml but that didn't work)

I've googled around this and while it must be explained somewhere, I am unable to find it. I asked a similar question a while back and though I appreciate the person answering, it didn't really address the crux of my confusion.

Community
  • 1
  • 1
Martin Hansen Lennox
  • 2,837
  • 2
  • 23
  • 64

1 Answers1

0

Well I have an answer, sort of.

I had mistakenly thought that MasterPages = Layout.chtml. Not true.

They're a similar concept but only used by the WebFormsViewEngine, not the RazorViewEngine.

As further explanation, I will quote heavily from this answer:

Starting with MVC3, the razor view engine was introduced. Razor doesn't allow you to use master pages.

MVC3 and 4 have another view engine called the WebForms view engine [that uses] master pages.

Master pages allow you to define content place holders, while razor allows you to define sections. Master pages render the page outside in, meaning first the master page, then the content place holders. Razor is I believe recursive and starts with the innermost section and works it's way back out.

So, it appears that the concept of master pages is not valid when using razor.

But my question still stands:

Why areMasterLocationFormats even included in the RazorViewEngine?

Please post an answer if you know - I will mark that as the correct one.

Community
  • 1
  • 1
Martin Hansen Lennox
  • 2,837
  • 2
  • 23
  • 64