[英]Not sure why I'm getting this C# error
错误是: Using the generic type 'System.Collections.Generic.List<T>' requires 1 type arguments
我不知道为什么会发生这种情况,请记住,我对 C# 非常陌生,还不完全了解如何使用它。 我正在尝试获取文件以从数据库表中检索一列并将其插入到带有额外标题的 CSV 文件中。 数据库表是 cmsDictionary,列是键,这应该填充 CSV 键列,其他应该是空白以供用户填充,然后将其导入 cmsLanguageText 表。
//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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.