2014-02-07 80 views
5

我在Visual Studio中遇到问题,在调用ViewBag的一行代码的我的MVC5剃须刀视图中出现错误。剃刀视图中的Mvc5 VS2013错误

@{ 
    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。仍然是同样的问题。

还有与添加任何拉姆达到视图的问题,如

@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问题。

任何帮助欢迎!

回答

5

在web.config中更改为targetFramework =“4.5.1”为我修复了它。