How to pass ExpandoObject as Model?
See original GitHub issueHello,
iam trying to pass a ExpandoObject as Model to the RazorLightEngineBuilder and always receive:
“InvalidOperationException: Can not resolve a content for the template “{0}” as there is no project set.You can only render a template by passing it’s content directly via string using coresponding function overload”
I dont understand the error in this case. Why do I need to set a project when the model changes? The quick and dirty code iam using:
var engine = new RazorLightEngineBuilder()
.UseMemoryCachingProvider()
.Build();
string template = "Hello, @Model.Name. Welcome to RazorLight repository";
dynamic expando = new ExpandoObject();
expando.Name = "John Doe";
string result = engine.CompileRenderAsync("templateKey", template, expando).Result;
When switching to a stronglyTyped Model it does work.
Any code samples showing me how to handle “dynamic properties”/ExpandoObject would be great!
Thanks alot!
Issue Analytics
- State:
- Created 5 years ago
- Comments:8
Top Results From Across the Web
passing ExpandoObject as parameter
I have some sql functions like this (wrote in C#): public void Query(string sqlText, ExpandoObject paramSet) { SqlCommand cmd = new ...
Read more >ExpandoObject Class (System.Dynamic)
The ExpandoObject class is an implementation of the dynamic object concept that enables ... You can pass instances of the ExpandoObject class as...
Read more >Pass Data using Session, Tuples, and Dynamic ...
This tutorial teaches you how can you use Session, Tuples, and Dynamic (ExpandoObject) for passing multiple model data into a single view page....
Read more >Building C# objects dynamically with ExpandoObject
Solution. Use ExpandoObject to create an object that you can add properties, methods, and events to and be able to data bind to...
Read more >Partial View Usage With Dynamic Expando Object and Tuple
First declare your Exapndo object to declare all your dynamic models in the controller. Here you can review my controller code in which...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@smcl Thanks! Hope my stepping into help Ivan maintain this is helping your company and projects out! This is a great project, so keep on giving this great feedback. Great communities = great open source software = YOU are a great person.
I don’t know what the original issue was, but with 2.0.0-betaX in
master
what’s happening is that this method is called:Which also fails. What @C0d1ngJammer probably wants (if they are still interested) is the
IRazorLightEngine.CompileRenderStringAsync()
method, so the original snippet would look like thisBoth strongly-typed objects and
dynamic
work fine in this scenario, I think it can be closed - unless @C0d1ngJammer has any objections?