Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MVC 5 AddView模板空模型类IEnumerable<;项目>;错误:已添加具有相同索引的项_C#_Asp.net_Asp.net Mvc - Fatal编程技术网

C# MVC 5 AddView模板空模型类IEnumerable<;项目>;错误:已添加具有相同索引的项

C# MVC 5 AddView模板空模型类IEnumerable<;项目>;错误:已添加具有相同索引的项,c#,asp.net,asp.net-mvc,C#,Asp.net,Asp.net Mvc,我想创建一个简单的Asp.NETMVC应用程序。当我尝试使用模型类“Product”添加名为“List”的空视图时,它会告诉我: 运行所选代码生成器“已添加具有相同索引的项”时出错 我使用Ninject的最新稳定版本,Ninject.MVC3,Moq public class ProductController : Controller { private IProductRepository repository; public ProductController (IProd

我想创建一个简单的Asp.NETMVC应用程序。当我尝试使用模型类“Product”添加名为“List”的空视图时,它会告诉我:

运行所选代码生成器“已添加具有相同索引的项”时出错

我使用Ninject的最新稳定版本,Ninject.MVC3,Moq

public class ProductController : Controller
{
    private IProductRepository repository;
    public ProductController (IProductRepository productRepository)
    {
        this.repository = productRepository;
    }

    public ViewResult List()
    {
        return View(repository.Products);
    }
}
更新1

IPR存储库代码

public interface IProductRepository
{
    IEnumerable<Product> Products { get;}
}
公共接口存储库
{
IEnumerable乘积{get;}
}
更新2


我已重新安装Visual Studio并修复了此问题。

验证IPProductRepository是否有两个具有相同密钥的属性(不区分大小写)。如果您有Id和Id,它将抛出该错误。IPProductRepository只有一个属性IEnumerable Products{get;}在什么时候会发生此错误?在代码中还是在视图中?在一篇帖子之后?@acastr7它发生在代码中。右键单击模型类的列表操作方法->添加视图->模板到空->产品,并选中“使用布局页面”框。在那之后,我犯了一个错误