我正在接受一个教程并在" List"上收到错误:

时间:2017-06-15 23:26:51

标签: asp.net-mvc controller

我正在学习一门教程(https://www.tutorialspoint.com/mvc_framework/mvc_framework_views.htm)并在" List"上出现错误:

public class ViewDemoController : Controller { 

    public class Blog { 
        public string Name; 
        public string URL; 
    }

    private readonly List topBlogs = new List {
         new Blog { Name = "Joe Delage", URL = "http://tutorialspoint/joe/"},
         new Blog {Name = "Mark Dsouza", URL = "http://tutorialspoint/mark"},
         new Blog {Name = "Michael Shawn", URL = "http://tutorialspoint/michael" }
    };

    public ActionResult StonglyTypedIndex() { 
        return View(topBlogs); 
    }

    public ActionResult IndexNotStonglyTyped() { 
        return View(topBlogs); 
    }

1 个答案:

答案 0 :(得分:0)

List是一个通用集合。我认为你的代码应该是

private readonly List<Blog> topBlogs = new List<Blog> {
     new Blog { Name = "Joe Delage", URL = "http://tutorialspoint/joe/"},

请注意,它是List<Blog>,而不仅仅是List。非通用列表集合是ArrayList,尽管它的使用几乎不像List。