I'm working on a web app using Asp.Net MVC and C#. Users are allowed to upload files which are done via jQuery ajax
. What I am trying to do is add each file name a user uploads to a List<string>
. For that I have the following code:
public class FileUploadController : Controller
{
private List<string> UploadedFileNames = new List<string>();
public List<string> AddFileNameToList(string fileName)
{
UploadedFileNames.Add(fileName);
return UploadedFileNames;
}
public JsonResult UploadFile(string fileName)
{
//save file to directory etc
AddFileNameToList(fileName);
return Json(new {});//relevant info for the user
}
}
With the above code each time I upload a file and add the filename to UploadedFileNames
the previous count is always 0 rather than the all including all the previous filenames.
Can someone tell me how to achieve this please.