smsohan / MvcMailer

A Mailer for ASP.Net MVC that forms the Email Body using MVC Views (Razor etc.) following Ruby on Rails ActionMailer style
MIT License
585 stars 176 forks source link

How to set the layout page? #91

Closed pantsclunk closed 11 years ago

pantsclunk commented 11 years ago

I have this code in my Welcome email file Welcome.cshtml

@{ Layout = "~/Views/UserMailer/_Layout.cshtml"; }

HTML View for UserMailer#Welcome

It sends the mail, however it is using the layout file for my website rather than the email layout file. Am I doing something wrong? If so, how can I get it to use the mailer _Layout template file?

This is the body of the email. Notice it is using the website layout file rather than the email layout file?

your logo here • Register • Log in • Home • About • Contact HTML View for UserMailer#Welcome © 2013 - My ASP.NET MVC Application

Thanks

pantsclunk commented 11 years ago

If I change the name of the layout page and set that name in the UserMailer.cs file it works fine. Not sure why I have to change the name. It seems to get confused if there is another file named _Layout. Closing issue.

Thanks for a great product! :)

lruckman commented 11 years ago

This doesn't fix the issue for me. Every once and a while it will use the correct layout however but then it always goes back to using the sites layout again.

bberman commented 10 years ago

This worked for me! Thank God. Couldn't figure out for the life of me what was wrong! I hope others find this when googling. It took me a while to find.

Ignoring Layout at page level. Defauting to _viewstart layout. Change name of mailer layout, rebuild, and you're good.

Thank you thank you thank you

ghost commented 10 years ago

Hi, changing the name is not working for me, either. Any suggestions?

jeffrfinn commented 10 years ago

Did you try changing the MasterName in the constructor of you CS file ?

That worked for me