question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using a layout file with embedded resources

See original GitHub issue

Hi. Thanks for this great project. It makes send nicely formatted emails so much easier.

Using the file system engine, I can include something like this in one of my templates

@{
    Layout = "_Layout";
}

I don’t want to relay the file system in prod so I’m looking at changing the engine to use embedded resources, however this results in an exception of Project can not find template with key _Layout.cshtml. Both files are embedded. Am I missing something here? I didn’t see much in the way of docs for layout files.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
maxbanascommented, Nov 16, 2020

For your embedded resource project, the key for _Layout.cshtml would be “EmailTemplates._Layout.cshtml”. So in NotificationDigest.cshtml, you would set the layout like this:

@{
    Layout = "EmailTemplates._Layout.cshtml";
}

If all your templates are within EmailTemplates/, and you don’t want to have to include “EmailTemplates” in the key, you can set the root namespace by doing something like this: .UseEmbeddedResourcesProject(typeof(Test).Assembly, "RazorLitePoc.Services.EmailTemplates")

Also see #378

0reactions
photomoosecommented, Feb 12, 2021

In case other people come here wondering why this isn’t working, note that there’s a DOT between the folder name (“EmailTemplates”) and the layout name (“_Layout.cshtml”), and not a SLASH.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - How can we add embedded resources to a file which ...
1 Answer. You'll need to create a . resources file containing the files you want to embed as resources, and then reference the...
Read more >
Reuse layouts with <include>
To efficiently reuse complete layouts, use the <include> and <merge> tags to embed one layout inside another.
Read more >
Embedded resources and Layout pages — MvcCodeRouting
I have created a MVC site that uses MvcCodeRouting to register routes for 2 'modules' - which are MVC sites where the content...
Read more >
Create resource files - .NET
Create a binary resource (.resources) file programmatically. You can then embed the file in an application executable or an application library ...
Read more >
ASP.NET Core (.csproj) Embedded Resources
I've previously blogged about how to have embedded resources in ASP. ... I figured I would show how the project.json translates to the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found