不知道为什么我收到这个C#错误

时间:2016-04-20 08:49:51

标签: c# sql umbraco7

错误是: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;
        }
    }
}

2 个答案:

答案 0 :(得分:2)

嗯,这条线似乎错了:

getList(List<Item> DictionaryItems);

应该是:

getList(DictionaryItems);

编译器错误应该在代码文件中给出一行错误。

答案 1 :(得分:-1)

将此作为您的方法定义:

<div id="content-container">
    <div id="page-content"> 
        <div class="row">   
            <div class="col-md-12">
                <div class="tab-base">
                    <ul class="nav nav-tabs">
                        <li class="active">
                            <a data-toggle="tab" href="#demo-lft-tab-1">Tab1</a>
                        </li>
                        <li>
                            <a data-toggle="tab" href="#demo-lft-tab-2">Tab2</a>
                        </li>
                        <li>
                            <a data-toggle="tab" href="#demo-lft-tab-3">Tab3</a>
                        </li>
                        <li>
                            <a data-toggle="tab" href="#demo-lft-tab-4">Tab4</a>
                        </li>
                    </ul>
                    <div class="tab-content">
                        <div id="demo-lft-tab-1" class="tab-pane fade active in"></div>
                        <div id="demo-lft-tab-2" class="tab-pane fade"></div>
                        <div id="demo-lft-tab-3" class="tab-pane fade"></div>
                        <div id="demo-lft-tab-4" class="tab-pane fade"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>          
</div>          
<script>
    var lastTab = localStorage.getItem('lastTab');
    if (!lastTab) {
        lastTab = 0;
    }
    $(".tab-base").tabs({
        activate: function(event, ui) {
            //if another tab is activate, save it's index to the localStorage
            localStorage.setItem('lastTab', ui.newTab.index());
        },
        //set the corresponding tab to active
        active: lastTab
    });
</script>
相关问题