【问题标题】:Mvc5 VS2013 errors in razor view剃刀视图中的 Mvc5 VS2013 错误
【发布时间】: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&lt;TModel,TValue&gt;(System.Web.Mvc.HtmlHelper&lt;TModel&gt;, System.Linq.Expressions.Expression&lt;System.Func&lt;TModel,TValue&gt;&gt;, System.Collections.Generic.IDictionary&lt;string,object&gt;)' cannot be inferred from the usage. Try specifying the type arguments explicitly

但奇怪的是,应用程序确实按预期运行,所以我认为这是某种 Visual Studio 问题。

欢迎任何帮助!

【问题讨论】:

    标签: c# razor visual-studio-2013 asp.net-mvc-5


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2017-02-21
      • 2015-10-25
      • 2018-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-06
      • 2015-07-15
      相关资源
      最近更新 更多