【发布时间】:2014-03-04 21:50:45
【问题描述】:
我在 Visual Studio 中遇到问题,我在调用 ViewBag 的代码行上的 MVC5 razor 视图中出现错误。
@{
ViewBag.Title = "Home Page";
}
错误是one or more types required to compile a dynamic expression, are you missing a reference。
我一直在寻找解决方案。一些帖子要求我添加对 Microsoft.Csharp v.4.0.30319 的引用。这已经完成,但问题仍然存在。另一种解决方案是添加行
<compilation debug="true" targetFramework="4.0" />
到配置文件。由于我的目标是 4.5,所以无法做到这一点,所以我将其更改为 4.5。还是一样的问题。
在视图中添加任何 lambda 也存在问题,例如
@Html.LabelFor(a=>a.Property);
这也会导致错误:
'System.Web.Mvc.Html.LabelExtensions.LabelFor<TModel,TValue>(System.Web.Mvc.HtmlHelper<TModel>, System.Linq.Expressions.Expression<System.Func<TModel,TValue>>, System.Collections.Generic.IDictionary<string,object>)' cannot be inferred from the usage. Try specifying the type arguments explicitly
但奇怪的是,应用程序确实按预期运行,所以我认为这是某种 Visual Studio 问题。
欢迎任何帮助!
【问题讨论】:
标签: c# razor visual-studio-2013 asp.net-mvc-5