I created a dynamic object like below:
dynamic myObject = new
{
DisplayName = "Mahesh"
};
Content = Parse("Main", myObject);

Then I parsed it for Razor template. But it doesnt work because of the object cannot access to its properties. What is the problem here ?
Thanks in advance,
The anonymous type has some accessibility issues, in that
dynamicvia the c# provider tries to respect accessibility. An anonymous type in a different module is not accessible (and remember that MVC pages will typically compile into a different module), hence no properties.IIRC, however, this is actually fixed in a later MVC patch – I seem to remember hitting this when my local machine was a rev higher than our dev-server, meaning: it worked locally on the higher revision, but failed as you describe on the dev-server.
The
ExpandoObjectdoes not suffer this because it does not use the c# provider (it implementsIDynamicMetaObjectProviderinstead), and has no concept of accessibility (it simply maps member-names to the dictionary).