Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use method 'IncludeAsync()' to import partial view in root view? #376

Open
lawtj93 opened this issue Aug 4, 2023 · 0 comments
Open

Comments

@lawtj93
Copy link

lawtj93 commented Aug 4, 2023

Hi:
I use the FluentEmail.Razor 3.0.2 in my .NET 6 project and it's working fine for most of what I need it to do.

I have a layout file _DefaultEmailLayout.cshtml that contains a basic header and footer, so in one of my template files ForgotPassword.cshtml i reference this layout file.

@model SharedLibrary.Models.Shared.EmailTemplate

@{
Layout = Model.LayoutLocation; //contains location of layout file
}

Your password

Hi @model.FirstName,

Need Help?

If you need any assistance, our Client Support Team are here to help. Feel free to reach out to our team via email on XXX

And in the code itself when I use the FluentEmail.UsingTemplateFromFile().SendAsync() it sends the email successfully and the email is received looking as expected with the layout files header and footer.

What I'm having trouble with is that a few of my emails share a section that you see in the ForgotPassword.cshtml file, the Need Help section, so instead of duplicating it in all those files I placed it in a separate file called _NeedHelpLayout.cshtml

Now if I replace that section in ForgotPassword.cshtml with the below

then when the email sends, the section is not only not parsed but it's not anywhere to be found, the email template just doesn't include it. Am I doing something wrong here?

I read that since it uses razorlight then I need to include something like the below

@{ await IncludeAsync("Test.cshtml", Model);}

however when I try to use this line i get the error " CS0103 The name 'IncludeAsync' does not exist in the current context "

Based off reading I found an example of where the include async didn't provide an error and that was when it had these 2 lines at the beginning of the file

@using RazorLight
@inherits TemplatePage

However I have a model that I need to include already that I need for the rest of my templates

@model SharedLibrary.Models.Shared.EmailTemplate

Hopefully I've shared enough details of the problem, if I've missed anything let me know

I know this issue is related to RazorLight too so if you think this issue should be posted over there I can move it. I posted it here because i'm using these templates to send with FluentEmail so I wasn't sure if it was something that someone here has experienced or it may be related to FluentEmail

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant