I want the infoBox1Image to be variable. For example it could also be Model.infoBox2Image.mediaItem. Is this possible? Can I make a variable (which is filled with an @parameter) and do Model.variable.mediaItem?
Model.getProperty doesn't seem to work. If getProperty could work somehow would .mediaItem afterwards still work or do I need to cast the value to something dynamic again?
Thanks. It works, but I can't use .mediaItem afterwards. If I try this:
Model.GetProperty("infoBox1Image").mediaItem
I get the following exception:
'Model.GetProperty("infoBox1Image").mediaItem' threw an exception of type 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException'dynamic {Microsoft.CSharp.RuntimeBinder.RuntimeBinderException}
Guess I need to convert it back to something again.
Razor variable property
Hello,
I've got a razor script that I want to make variable. Here is my script:
I want the infoBox1Image to be variable. For example it could also be Model.infoBox2Image.mediaItem. Is this possible? Can I make a variable (which is filled with an @parameter) and do Model.variable.mediaItem?
Jeroen
You could try to us getProperty. This is untested.
Model.getProperty doesn't seem to work. If getProperty could work somehow would .mediaItem afterwards still work or do I need to cast the value to something dynamic again?
Jeroen
Sorry, it should be capital G. Model.GetProperty()
Thanks. It works, but I can't use .mediaItem afterwards. If I try this:
I get the following exception:
'Model.GetProperty("infoBox1Image").mediaItem' threw an exception of type 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' dynamic {Microsoft.CSharp.RuntimeBinder.RuntimeBinderException}
Jeroen
I got it working with the following code:
I add a DynamicXml function because I'm going to use it a lot more. It will be moved to another file, but is here for the example :).
Jeroen
Refactored (for 4.7.1), this would look like:
Just tested Sebastiaan his example, but it should be Model.GetPropertyValue(Parameter.PropName) instead.
Jeroen
is working on a reply...