我在Visual Studio中收到此错误:
错误CS7003意外使用未绑定的通用名称MyProject C:\ Users [myname] \ documents \ visual studio 2015 \ Projects .... \ Index.cshtml 1
违规文件就在这里(第1行错误是对模型声明的引用):
@model MyProject.Models.MyAccount.Details
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_PrimaryLayout.cshtml";
}
<!-- Page Content -->
<div class="container">
.... more page stuff follows from here
模型类如下:
namespace MyProject.Models.MyAccount
{
public class Details
{
public static Details Select(Company c)
{
Details model = new Details();
model.SomeProperty = "SomeValue";
return model;
}
public String SomeProperty { get; set; }
}
}
奇怪的是,清理不会让它消失,重建将它留在那里,我建立/调试就好了。
答案 0 :(得分:36)
关闭Visual Studio并重新启动以清除错误。后续重建不会产生错误。
答案 1 :(得分:7)
我犯了一个错误,花了我很长时间才看到。 我创建了一个通用方法:
public static T MyMethod<T>() { ... }
错误地,我在我的代码中写道
var something = MyMethod<>();
它已编译但在运行时它抛出错误&#34;意外使用未绑定的通用名称&#34;。
如果您犯了同样的错误,可以尝试搜索&#34;&lt;&gt;&#34;在你的代码......
答案 2 :(得分:3)
我有同样的信息。 我在第一行移动了@model,错误就消失了。
答案 3 :(得分:1)
只需剪切@model
行并保存,然后再次粘贴并保存,就可以了。