Skip to content

@model and Visual Studio IntelliSense

Julian Verdurmen edited this page Jul 22, 2021 · 4 revisions

The @model syntax is not supported. See issue 14

If you like to have IntelliSense in Visual Studio, you could use @inherits and RazorEngineTemplateBase<T>

For example, instead of writing:

@model MyModel

write this:

@inherits RazorEngineCore.RazorEngineTemplateBase<MyModel>

Error message with @model

Warning, if you use @model in your template, you will get a funky error like this:

RazorEngineCore.RazorEngineCompilationException
Unable to compile template: j2rpxc2v.45u(7,7): error CS0103: The name 'model' does not exist in the current context
   at RazorEngineCore.RazorEngine.CreateAndCompileToStream(String templateSource, RazorEngineCompilationOptions options)
   at RazorEngineCore.RazorEngine.Compile[T](String content, Action`1 builderAction)