You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@adoconnection thanks for clarifications. Checked that @using works.
Note @inherites cannot be used for classes without parameterless constructor. So @model would be nice to support (e.g. just ignore it on compile time).
@adoconnection, parse the usings is little bit reasonable. Is it possible for me to do some work here? :) @sergeyt, I mention something under #50 may help.
@garryxiao sure, the only thing is I would like it to be done using Razor tools, sinse razor somehow parse them there should be a way to get usings collection. But I was not able to find out how.
There is always a plan B to use regex or something on a template string, I would like to avoid that.
Note @inherites cannot be used for classes without parameterless constructor.
Is this really true? I tried it and don't see the issue? (check IntelliSense, compiling and running?)
it can be a documented limitation/behavior. @model is for VS
I really prefer support for parsing @model and documenting this behavior. Maybe also with a better error message? If we use now @model MyModel, we get this error:
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)
I'm having an issue where I'm trying to use the example for @include and Template, combined with the example for strongly-typed models using @inherit Base.
The problem is that the templating approach shows you should use a MyTemplateBase, but that's not generic, so I can't put @include MyTemplateBase<MyModel> at the top as it doesn't accept T. I tried making it generic, but got stuck here:
It seems like maybe this wrapper is only required when the model is an anonymous type, based on here:
So in my case I can probably just remove that code. Will see how I go
Right, without AnonymousTypeWrapper Razor will not be able to read properties of supplied anonymous object
On the topic: The model is handled by the template, but if it happens @model directive is present, an exception is thrown at compile. Is there a way to ignore this directive and keep on compiling?
Activity
adoconnection commentedon Apr 17, 2020
@modelis controlled by RazorEngineCore itself so you dont need to use this directive and need to remove it from your template.@usingis supported too. Most likely you will need to explicitly link assembly https://github.com/adoconnection/RazorEngineCore/wiki/@Inject-and-referencing-other-assemblies#linking-assemblies(I was unable to parse @using-s and do it programatically in a reasonable time)
adoconnection commentedon Apr 17, 2020
To keep intellisense suggestions use
@Inheritsinstead of@modelhttps://github.com/adoconnection/RazorEngineCore/wiki/Switch-from-RazorEngine-cshtml-templates#template
sergeyt commentedon Apr 17, 2020
@adoconnection thanks for clarifications. Checked that
@usingworks.Note
@inheritescannot be used for classes without parameterless constructor. So@modelwould be nice to support (e.g. just ignore it on compile time).[-]Request: support @model and @using directives[/-][+]Request: support @model directive[/+]adoconnection commentedon Apr 22, 2020
@sergeyt wont it be hidden surprice, if someone will put
@model TypeAdirective and then figure out it was ignored and replaced by RazorEngineCode?sergeyt commentedon Apr 22, 2020
@adoconnection it can be a documented limitation/behavior.
@modelis for VS intellisense wheen@inheritsis not applicablegarryxiao commentedon May 12, 2021
@adoconnection, parse the usings is little bit reasonable. Is it possible for me to do some work here? :)
@sergeyt, I mention something under #50 may help.
adoconnection commentedon May 12, 2021
@garryxiao sure, the only thing is I would like it to be done using Razor tools, sinse razor somehow parse them there should be a way to get usings collection. But I was not able to find out how.
There is always a plan B to use regex or something on a template string, I would like to avoid that.
304NotModified commentedon Jul 21, 2021
Please include this in the wiki, or make the wiki public so I could add it :)
adoconnection commentedon Jul 21, 2021
@304NotModified wiki is open now :)
304NotModified commentedon Jul 22, 2021
Done! https://github.com/adoconnection/RazorEngineCore/wiki/@model-and-Visual-Studio-IntelliSense
304NotModified commentedon Jul 22, 2021
Is this really true? I tried it and don't see the issue? (check IntelliSense, compiling and running?)
I really prefer support for parsing
@modeland documenting this behavior. Maybe also with a better error message? If we use now@model MyModel, we get this error:Any leads where to start to get this implemented?
benmccallum commentedon Aug 13, 2021
I'm having an issue where I'm trying to use the example for @include and Template, combined with the example for strongly-typed models using @inherit Base.
The problem is that the templating approach shows you should use a

MyTemplateBase, but that's not generic, so I can't put@include MyTemplateBase<MyModel>at the top as it doesn't acceptT. I tried making it generic, but got stuck here:benmccallum commentedon Aug 13, 2021
It seems like maybe this wrapper is only required when the model is an anonymous type, based on here:
RazorEngineCore/RazorEngineCore/RazorEngineCompiledTemplate.cs
Lines 94 to 97 in a86a24b
So in my case I can probably just remove that code. Will see how I go
adoconnection commentedon Aug 14, 2021
Right, without
AnonymousTypeWrapperRazor will not be able to read properties of supplied anonymous objectseppo498573908457 commentedon Sep 21, 2023
On the topic: The model is handled by the template, but if it happens @model directive is present, an exception is thrown at compile. Is there a way to ignore this directive and keep on compiling?