-
Notifications
You must be signed in to change notification settings - Fork 85
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
Can I use the @model type directive in my template? #12
Comments
I might be wrong, but as I can see Have a look:
RazorEngineCore (me) adds two directives:
And then RazorEngine (Microsoft) will turn it in following code: #pragma checksum "vadrkp0x.pba" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "7292c67fd2ce79b6a8a3b20c73e811dee742b3ad"
// <auto-generated/>
#pragma warning disable 1591
namespace TemplateNamespace
{
using System.Linq;
public class Template : RazorEngineCore.RazorEngineTemplateBase
{
public async override global::System.Threading.Tasks.Task ExecuteAsync()
{
WriteLiteral("\r\n");
Write(model); // HERE - default RazorEngine instance thought @model is a variable name
WriteLiteral(" string\r\nHello ");
Write(Model);
WriteLiteral("\r\n");
}
}
} Why it is so important for you to have @model directive in template? |
I only find including the @model directive useful because it lets my editor (Visual Studio 2019) know the type and subsequently offer intellisense. What I will do is leave it in my templates (for editing purposes) but remove it before processing it with your library. Thanks so much for your response and your open source work! |
you welcome |
@dalenewman this is how you can use IntelliSense in your templates: #13 |
It might just be me, but I get an error saying "The name 'model' does not exist in the current context" whenever I have a @model directive in my strongly typed template. It runs without it, but I'd rather have it there than not. I've been through the gamut trying fixes outlined in this and this stack overflow post.
The text was updated successfully, but these errors were encountered: