RazorEngine icon indicating copy to clipboard operation
RazorEngine copied to clipboard

Known Model type with dynamic Property not working

Open Robiwahn23 opened this issue 7 years ago • 0 comments

I want to have a model class like this:

class MyModel {
  public dynamic Inner { get; set; }
}

but when i want to use it (e.g. with anonymous class with property IsDuplicate) ...

var model = new MyModel() { Inner = new { IsDuplicate = true } }

... the RunCompile method throws this exception: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'object does not contain a definition for IsDuplicate.'

Possible Template:

@model MyModel

@if(Model.Inner.IsDuplicate) { ... }

Do i need to use the RazorDynamicObject class somehow? Or is this functionality not supported?

Thank you for any help!

Robiwahn23 avatar Jan 04 '18 14:01 Robiwahn23