类型或命名空间名称错误 [英] The type or namespace name err

查看:110
本文介绍了类型或命名空间名称错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[HttpPost]
       [ValidateAntiForgeryToken]
       public ActionResult Upload(HttpPostedFileBase upload)
       {
           if (ModelState.IsValid)
           {

               if (upload != null && upload.ContentLength > 0)
               {

                   if (upload.FileName.EndsWith(".csv"))
                   {
                       Stream stream = upload.InputStream;
                       DataTable csvTable = new DataTable();
                       using (CsvReader csvReader =
                           new CsvReader(new StreamReader(stream), true))
                       {
                           csvTable.Load(csvReader);
                       }
                       return View(csvTable);
                   }
                   else
                   {
                       ModelState.AddModelError("File", "This file format is not supported");
                       return View();
                   }
               }
               else
               {
                   ModelState.AddModelError("File", "Please Upload Your file");
               }
           }
           return View();
       }







错误:






Error:

Error	1	The type or namespace name 'CsvReader' could not be found (are you missing a using directive or an assembly reference?)





如此友好地纠正以上提到的代码(MVC 4)



我的尝试:





so kindly rectify above mentioned code (MVC 4)

What I have tried:

[HttpPost]
       [ValidateAntiForgeryToken]
       public ActionResult Upload(HttpPostedFileBase upload)
       {
           if (ModelState.IsValid)
           {

               if (upload != null && upload.ContentLength > 0)
               {

                   if (upload.FileName.EndsWith(".csv"))
                   {
                       Stream stream = upload.InputStream;
                       DataTable csvTable = new DataTable();
                       using (CsvReader csvReader =
                           new CsvReader(new StreamReader(stream), true))
                       {
                           csvTable.Load(csvReader);
                       }
                       return View(csvTable);
                   }
                   else
                   {
                       ModelState.AddModelError("File", "This file format is not supported");
                       return View();
                   }
               }
               else
               {
                   ModelState.AddModelError("File", "Please Upload Your file");
               }
           }
           return View();
       }







错误:






Error:

Error	1	The type or namespace name 'CsvReader' could not be found (are you missing a using directive or an assembly reference?)





如此友好地纠正以上提到的代码(MVC 4)



so kindly rectify above mentioned code (MVC 4)

推荐答案

您尝试使用的类CsvReader不是.NET Framework的一部分。它必须在某个外部的.DLL中。你可以从你复制的代码的任何地方得到它。



然后你必须添加一个对该.DLL的引用,然后导入由它暴露的命名空间。包含CsvReader类的DLL。
The class you're trying to use, CsvReader, is not part of the .NET Framework. It has to be in an external .DLL somewhere. You can probably get that from wherever you got the code you copied.

You then have to add a Reference to that .DLL and then import the namespace exposed by that .DLL that contains the CsvReader class.


这篇关于类型或命名空间名称错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆