不确定为什么会出现此 C# 错误

Not sure why I'm getting this C# error

错误是:Using the generic type 'System.Collections.Generic.List<T>' requires 1 type arguments

我不知道为什么会这样,请注意我是 C# 的新手,还不完全了解如何使用它。我正在尝试获取文件以从数据库 table 中检索列并将其插入到带有额外 headers 的 CSV 文件中。 数据库 table 是 cmsDictionary 并且列是键,这应该填充 CSV 键列,其他的应该是空白的,由用户填充,然后将导入到 cmsLanguageText table.

//This is my controller file which is throwing the error.

using UmbracoImportExportPlugin.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using System.Text;
using Umbraco.Core.Persistence;
using Umbraco.Web;
using Umbraco.Web.WebApi;
using System.Data;
using System.Data.SqlClient;

namespace UmbracoImportExportPlugin.App_Code
{
    public class ExportDictionaryAllController : UmbracoAuthorizedApiController
    {

        [System.Web.Http.AcceptVerbs("GET", "POST")]
        public static void ExportAll(List<Item> DictionaryItems)
        {
            getList(List<Item> DictionaryItems);
            string attachment = "attachment; filename= DictionaryItems.csv";
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.ClearHeaders();
            HttpContext.Current.Response.ClearContent();
            HttpContext.Current.Response.AddHeader("Content-Disposition", attachment);
            HttpContext.Current.Response.ContentType = "text/csv";
            HttpContext.Current.Response.AddHeader("Pragma", "public");
            WriteColumnName();
            foreach (Item item in DictionaryItems)
            {
                WriteItemInfo(item);
            }
            HttpContext.Current.Response.End();
        }

        private static void WriteItemInfo(Item item)
        {
            StringBuilder sb = new StringBuilder();
            AddComma(item.Key, sb);
            AddComma(item.English, sb);
            AddComma(item.Hebrew, sb);
            AddComma(item.Russian, sb);
            HttpContext.Current.Response.Write(sb.ToString());
            HttpContext.Current.Response.Write(Environment.NewLine);
        }

        private static void AddComma(string value, StringBuilder sb)
        {
            sb.Append(value.Replace(',', ' '));
            sb.Append(", ");
        }

        private static void WriteColumnName()
        {
            string columnNames = "Key, English, Hebrew, Russian";
            HttpContext.Current.Response.Write(columnNames);
            HttpContext.Current.Response.Write(Environment.NewLine);
        }

        public List<String> getList(List<Item> DictionaryItems)
        {
            UmbracoDatabase db = ApplicationContext.DatabaseContext.Database;
            var select = new Sql("SELECT key FROM cmsDictionary");
            List<Item> DictionaryItems = db.Fetch<Item>(select);
            return DictionaryItems;
        }
    }
}

嗯,这行好像错了:

getList(List<Item> DictionaryItems);

应该是:

getList(DictionaryItems);

编译器错误应该会在错误所在的代码文件中为您提供一行。

使用这个作为你的方法定义:

public static List<String> getList(List<Item> DictionaryItems) 
{ 
  UmbracoDatabase db = ApplicationContext.DatabaseContext.Database; 
  var select = new Sql("SELECT key FROM cmsDictionary"); 
  List<string> DictionaryItems = db.Fetch<Item>(select); 
  return DictionaryItems; 
}