2014-02-07 77 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」爲我修復了它。