Possible Duplicate:
Dynamic Anonymous type in Razor causes RuntimeBinderException
I am trying to use a dynamic type model in my MVC application. I have the following code: in controller:
var model = new { Name = "test name", Family = "m" };
return this.View(model);
and in the view I have:
@model dynamic
@if(Model!=null)
{
<p> @Html.Raw(Model.Name) </p>
}
When I am running this, I am getting the following error :
'object' does not contain a definition for 'Name' (System.Exception {Microsoft.CSharp.RuntimeBinder.RuntimeBinderException)
Why do I get this error? During debug, if I put my cursor on @Model, I can see that it has two property called Name and Family.