5

Is it possible to use a layout from another assembly? I spitted up my application in different layers and have a separated UI layer which contains the master layout for the designers to edit.

Is it possible and what I what would my reference looks like?

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
tereško
  • 58,060
  • 25
  • 98
  • 150
René Stalder
  • 2,536
  • 5
  • 31
  • 50

2 Answers2

0

At the end by the time you run the website, you need to gather all the views including layouts to a known place.

In this case you can copy the shared views under root

<siteroot>/Views/Shared/

With this assumption you can refer these layouts the way you are doing. However visual studio or tools like resharper keep showing this as an error. You need to get comfortable with those errors.

chandmk
  • 3,496
  • 3
  • 21
  • 26
  • So it's not possible to use the common way and having a url like `Layout = assembly.namespace;`? – René Stalder Jan 28 '12 at 21:24
  • I don't think MVC layouts are pragmatically accessible that way. Also if you think about it providing paths is simple and less expensive at runtime. – chandmk Jan 28 '12 at 21:27
-1

You may take a look at the following article which illustrates a technique allowing you to have Razor views embedded into a separate assembly.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928