【发布时间】:2013-05-21 09:16:27
【问题描述】:
当我尝试在 ASP.NET MVC 3 中添加强类型视图时,我收到以下错误:
我重新启动 Visual Studio,重建项目,再次尝试添加视图并得到以下结果:
我的模特:
public class SimpleModel
{
public int ID { get; set; }
public string Name { get; set; }
public bool IsActive { get; set; }
}
我的控制器:
public class TestController : Controller
{
public ActionResult Test()
{
return View(new SimpleModel());
}
}
问题是环境范围的(我创建了一个新项目并尝试添加视图,结果相同)并且无法通过重新启动 Visual Studio 或我的开发机器来解决。
编辑:只需重新安装 ASP.NET 和 Web Tools 2012.2 即可解决问题。
【问题讨论】:
-
是否都添加了
System.ComponentModel.DataAnnotations.dll和System.Core.dll作为对项目的引用? -
@RobH System.ComponentModel.DataAnnotations 被引用,但 System.Core 不是。当我尝试手动添加它时,我收到以下错误:无法添加对“System.Core”的引用。该组件已被构建系统自动引用。
-
看起来Visual Studio 无法访问System.ComponentModel.DataAnnotations.dll,你能把它安装到GAC 中吗?
-
或者我认为您可以使用 ProcessMonitor 找出 Visual Studio 尝试搜索该 dll 的确切位置。
标签: c# asp.net-mvc visual-studio t4 strongly-typed-view