Using Razor to create templates and views is very simple, elegant and easy to understand. But when you want to share a few lines of code, a function or some constants between views, you need a simple trick.
No DLLs - good and bad
Basically when we're just working with razor, then there is no officially compiled code. In reality, every Razor is also compiled to code - but this is background-magic outside of your control. So to share a few lines of code, we do the following.
Create a "shared" file
Remember to name it with "_" at the beginning, to prevent the file from ever being accessed directly through the web. Now place some code in - inside an @function block - which will be reused. This example shows the shared bits of the Blog App in the "_library.cshtml":