c# - Razor View 中的 Mvc5 VS2013 错误

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

我在 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/

相关文章:

c# - 如何(单元)测试弱引用列表的内存管理功能?

c# - 确定 Python/IronPython 函数的声明顺序

c# - Bouncy CaSTLe TLS API 用法

razor - URL.Page 对 ASP.Core Identity 返回 null

javascript - 在 Telerik MVC 中使用客户端传递参数

visual-studio - 如何仅在 SQL 查询中禁用 visual studio intellisense?

c# - ASCII编码和编码之间的区别

angularjs - 使用 Angular JS 在 ASP .Net MVC 中进行表单验证

c# - 当我按 F5 时,会打开一个 "Attach to Process"窗口

excel - Visual Studio 在线 : No Reports on Team Server possible?