lukencode / FluentEmail

All in one email sender for .NET. Supports popular senders (SendGrid, MailGun, etc) and Razor templates.

Home Page:https://lukelowrey.com/dotnet-email-guide-2021/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

lawtj93 opened this issue · comments

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