Razor 视图引擎:表达式树可能不包含动态操作 [英] Razor View Engine : An expression tree may not contain a dynamic operation

查看:27
本文介绍了Razor 视图引擎:表达式树可能不包含动态操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似的模型:

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)

这是错误:

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!

推荐答案

在我看来,您有一个无类型视图.默认情况下,MVC3 RC 中的 Razor 视图类型为 dynamic.但是,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

这篇关于Razor 视图引擎:表达式树可能不包含动态操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆