Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.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# 如何在tempdatamvc4中存储路径字符串数组_C#_Asp.net Mvc_Json_Asp.net Mvc 3_Asp.net Mvc 4 - Fatal编程技术网

C# 如何在tempdatamvc4中存储路径字符串数组

C# 如何在tempdatamvc4中存储路径字符串数组,c#,asp.net-mvc,json,asp.net-mvc-3,asp.net-mvc-4,C#,Asp.net Mvc,Json,Asp.net Mvc 3,Asp.net Mvc 4,我在代码中得到了操作结果,该代码从视图中逐文件返回图像 [HttpPost] public ActionResult UploadFiles(IEnumerable<HttpPostedFileBase> files) { if (!Directory.Exists(Server.MapPath("~/TempImages/")) || files != null) { string TempPat

我在代码中得到了操作结果,该代码从视图中逐文件返回图像

[HttpPost]       
    public ActionResult UploadFiles(IEnumerable<HttpPostedFileBase> files)
    {
        if (!Directory.Exists(Server.MapPath("~/TempImages/")) || files != null)
        {
            string TempPath = Server.MapPath("~/TempImages/");
            string[] myTempPaths = new string[files.Count()];
            foreach (HttpPostedFileBase file in files)
            {
                string filePath = Path.Combine(TempPath, file.FileName);
                System.IO.File.WriteAllBytes(filePath, ReadData(file.InputStream));
                file.SaveAs(filePath);
                for (int i = 0; i < files.Count(); i++)
                {                        
                    myTempPaths = filePath.Split(',');
                    for (int j = 0; j < files.Count(); j++)
                    {
                        TempData["lev1"] = myTempPaths;
                        for (int k = 0; k < files.Count(); i++)
                        {

                        }
                    }
                }                    
            }
        }
[HttpPost]
公共操作结果上载文件(IEnumerable文件)
{
如果(!Directory.Exists(Server.MapPath(“~/tempmages/”)| | files!=null)
{
字符串TempPath=Server.MapPath(“~/TempImages/”);
string[]MyTempPath=新字符串[files.Count()];
foreach(文件中的HttpPostedFileBase文件)
{
字符串filePath=Path.Combine(TempPath,file.FileName);
System.IO.File.writealBytes(文件路径,ReadData(File.InputStream));
file.SaveAs(文件路径);
对于(int i=0;i
我想在tempdata中存储每个转弯的路径 假设我有三张图片,动作将输入此方法三次,每次输入下一张图片的路径
但是我在中间迷失了方向。< / P> < P>这是我从你那里得到的…无论它是什么。 你想保存文件然后返回它们的路径

[HttpPost]       
public ActionResult UploadFiles(IEnumerable<HttpPostedFileBase> files)
{
    // reject if no file is send
    if(files == null || !files.Any())
    {
        // return error or throw exception
    }

    // create folder if not exist
    if(!Directory.Exists(Server.MapPath("~/TempImages/")))
    {
        // create folder
    }

    // base path for images
    string TempPath = Server.MapPath("~/TempImages/");
    // list to save file paths
    List<string> myTempPaths = new List<string>();


    foreach (HttpPostedFileBase file in files)
    {
        string filePath = Path.Combine(TempPath, file.FileName);

        // save file
        file.SaveAs(filePath);

        // add path to list
        myTempPaths.Add(filePath);
    }

    // save paths into temp Data
    TempData["lev1"] = myTempPaths;

    return View();
}
[HttpPost]
公共操作结果上载文件(IEnumerable文件)
{
//如果未发送任何文件,则拒绝
如果(files==null | |!files.Any())
{
//返回错误或抛出异常
}
//创建文件夹(如果不存在)
如果(!Directory.Exists(Server.MapPath(“~/tempmages/”)存在)
{
//创建文件夹
}
//图像的基本路径
字符串TempPath=Server.MapPath(“~/TempImages/”);
//保存文件路径的列表
List MyTempPath=新建列表();
foreach(文件中的HttpPostedFileBase文件)
{
字符串filePath=Path.Combine(TempPath,file.FileName);
//保存文件
file.SaveAs(文件路径);
//将路径添加到列表
添加(文件路径);
}
//将路径保存到临时数据中
TempData[“lev1”]=MyTempPath;
返回视图();
}

问题不够清楚,无法回答,请更正。您从操作中返回了什么?带图像的操作返回您有一个索引为
i
的for循环嵌套在另一个索引为
i
的for循环中。非常确定这行不通。不仅不清楚,而且它甚至不是正常代码。这是什么?