Hi Matt,
Sorry about the big load of questions, but I believe I am nearing the end :D
I am now sending a static email and it works fine. I receive the mail, after the order is finished.
As your view file is a razor file, you can use regular razor syntax. So, in your template at the top you'll want to add a @model directive to tell your view what model type to expect
@model NameSpace.TestClass
and then within your markup, you can use razors output abilities like the following to render value out
The Namespace in the following snippet, I'd figure would be the NameSpace where the TestClass is defined?
Is yes how do I go about it, when the TestClass is defined in my Core Library
While the template is in the main project.
What would be the best course of action to refer to it?
That is correct, and again, as per regular .NET practice as long as the main project has the core DLL in it's bin folder and your TestClass is public, it should pick it up.
I am trying to setup the model as shown by you earlier
like this
@model FridayHome.core.ClassTest;
However I keep getting this error in Visual Studio:
ClassTest is a type, which is not valid in the given context
Only Assignment, call, increment, decrement, await and new object expressions can be used as a statement
I also get an XML error when the event actually gets triggered...
@using FridayHome.core.Services;
@model FridayHome.core.ClassTest;
<html lang="en">
ClassTest is a type, which is not valid in the given context
Only Assignment, call, increment, decrement, await and new object expressions can be used as a statement
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<h1>The test value is @(Model.test)</h1>
</body>
</html>
Using object data in email template
Hi Matt,
Sorry about the big load of questions, but I believe I am nearing the end :D I am now sending a static email and it works fine. I receive the mail, after the order is finished.
I am passing a simple class in the
_emailTemplateService.SendEmail(emailTemplate, testClass, "[email protected]", "en-gb");
The class looks like this:
Sorry to ask such a broad question, but how do I go about using the object data in the email template?
Hi Victor,
No problem.
As your view file is a razor file, you can use regular razor syntax. So, in your template at the top you'll want to add a
@model
directive to tell your view what model type to expectand then within your markup, you can use razors output abilities like the following to render value out
Hope this helps
/Matt
Okay, that makes sense.
The Namespace in the following snippet, I'd figure would be the NameSpace where the TestClass is defined? Is yes how do I go about it, when the TestClass is defined in my Core Library While the template is in the main project. What would be the best course of action to refer to it?
Hi Victor,
That is correct, and again, as per regular .NET practice as long as the main project has the core DLL in it's bin folder and your TestClass is public, it should pick it up.
/Matt
Hi Matt,
I am trying to setup the model as shown by you earlier like this
However I keep getting this error in Visual Studio:
I also get an XML error when the event actually gets triggered...
What's the markup to your whole template? Sounds like it may be malformed.
Matt
Can you try it without the
;
on the end of your@model
statement?That was it!!
Thanks a lot, my mailevent seems to be working just fine now! :D
Great stuff 👍
is working on a reply...