Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从类获取数据到控制器_C#_Asp.net Mvc_Linq - Fatal编程技术网

C# 从类获取数据到控制器

C# 从类获取数据到控制器,c#,asp.net-mvc,linq,C#,Asp.net Mvc,Linq,我正在尝试将AllPath变量获取到控制器,以便从db下载文件。 这是课程: 我会在你的控制器里做这些,你根本不需要搞乱它 你面临的实际问题是什么?您正在调用GetSpecificYears(…)方法,但没有对其执行任何操作?路径是什么?文件是否存储在数据库中&如果是什么格式,PDF?@StuartFrankish是的,它们是PDF。很抱歉,我没有更正确地问这个问题。我更改了getyears.GetSpecificYears(年)的代码行;to var allYears=getyears.Get

我正在尝试将AllPath变量获取到控制器,以便从db下载文件。 这是课程:

我会在你的控制器里做这些,你根本不需要搞乱它


你面临的实际问题是什么?您正在调用
GetSpecificYears(…)
方法,但没有对其执行任何操作?路径是什么?文件是否存储在数据库中&如果是什么格式,PDF?@StuartFrankish是的,它们是PDF。很抱歉,我没有更正确地问这个问题。我更改了getyears.GetSpecificYears(年)的代码行;to var allYears=getyears.GetSpecificYears(年);。。现在我正试图下载控制器中那个变量上的文件。这正是我最后要做的,谢谢。
public class DBQueries 
{


    public List<string> GetSpecificYears(string[] response)
    {
        List<string> allPaths = new List<string>();


        if (response != null)
        {
            using (var db = new FMBDBPRDEntities1())
            {
                foreach (var aYear in response)
                {

                    List<string> paths = db.ClientStatement_Inventory
                                           .Where(x => x.statementYear == aYear)
                                           .Select(y => y.statementPath).ToList();

                    allPaths.AddRange(paths);
                }
            }
        }
        return allPaths; // or do whatever with your total results
    }
}
public ActionResult ExportFile(string[] years, string[] months, string[]radio, string[] acctNum)
    {

        ClientStatement_Inventory theStatementPath = new ClientStatement_Inventory();
        var thePath = theStatementPath.statementPath;

        DBQueries getyears = new DBQueries();
        var allPaths = getyears.GetSpecificYears(years);

        var cd = new ContentDispositionHeaderValue("attachment")
        {
            FileNameStar = theStatementPath.statementPath
        };
        Response.AppendHeader("Content-Disposition", cd.ToString());

        return File(theStatementPath.statementPath, theStatementPath.statementPath);

    }