我在 Visual Studio 中遇到问题,我的 MVC5
中出现错误调用 ViewBag 的代码行上的 Razor View 。
@{
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。还是一样的问题。
在 View 中添加任何 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 问题。
欢迎任何帮助!
最佳答案
在 web.config 中更改为 targetFramework="4.5.1"为我修复了它。
关于c# - Razor View 中的 Mvc5 VS2013 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21628517/