I have a model similar to this:
public class SampleModel
{
public Product Product { get; set; }
}
And in my controller I get an exception trying to print out
@Html.TextBoxFor(p => p.Product.Name)
This is the error:
Exception: An expression tree may not contain a dynamic operation
If anyone can give me some clues on how to fix this I would really appreciate it!
In this link explain about @model, see a excerpt:
It seems to me that you have an untyped view. By default, Razor views in MVC3 RC are typed as
dynamic
. However, lambdas do not support dynamic members. You have to strongly type your model. At the top of your view file addBefore using (strongly type html helper into view) this line
You should include your model into you page for making strongly type view.
This error happened to me because I had @@model instead of @model... copy & paste error in my case. Changing to @model fixed it for me.
A common error that is the cause of this is when you add
at the top of the page instead of
Seems like your view is typed
dynamic
. Set the right type on the view and you'll see the error go away.