剃刀视图引擎:一个EX pression树不能包含动态操作

问题描述:

我有一个类似的模式:

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)

异常:EX pression树不能包含动态操作

Exception: An expression tree may not contain a dynamic operation

如果任何人都可以给我如何解决这一问题的一些线索,我真的AP preciate了!

If anyone can give me some clues on how to fix this I would really appreciate it!

在我看来,你有一个类型化的观点。默认情况下,在MVC3 RC剃刀意见类型为动态。但是,lambda表达式不支持动态成员。你必须强类型模型。在你的视图文件的顶部添加

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 add

@model SampleModel