Visual Studio를 사용하여 ASP.NET MVC에서 파일을 다운로드하는 데 문제가 있습니다. 내 코드의 주요 목적은 내 로컬 파일 시스템에 라이센스 파일을 저장하는 것입니다. 내 업로드 기능이 정상적으로 작동하지만 다운로드 기능이 정상적으로 작동하지 않습니다. 내가 사용하는 데이터베이스가 목록을 저장할 수 없기 때문에 현재 각 파일 이름을 "9-0.lic, 9-1.lic, 9-2.lic"와 같은 문자열로 저장합니다. 첫 번째 숫자 (9)는 Software License Model의 기본 키이고 대시 다음의 숫자는 라이센스 파일 번호 (1, 2 및 3)입니다.여러 파일 다운로드 중. ASP.NET MVC C#
SoftwareLicense 모델 :
public class SoftwareLicense
{
[Key]
public int SoftwareID { get; set; } // Properties of class SoftwareLicense
public int UserID { get; set; }
[ForeignKey("UserID")]
public virtual IntranetUser User { get; set; }
[Required(ErrorMessage = "Software title field is required.")]
[Display(Name = "Software Title")]
public string SoftwareName { get; set; }
[Required(ErrorMessage = "The software key field is required")]
[Display(Name = "Software Key")]
public string SoftwareKey { get; set; }
[Required(ErrorMessage = "The software price field is required")]
[Display(Name = "Software Price")]
public decimal Price { get; set; }
[Display(Name = "License File")]
public string LicenseFileName { get; set; }
[Display(Name = "File Path")]
public string LicenseFilePath { get; set; }
[Required(ErrorMessage = "The start date field is required.")]
[Display(Name = "Start Date")]
public DateTime StartDate { get; set; }
[Required(ErrorMessage = "The end date field is required")]
[Display(Name = "End Date")]
public DateTime EndDate { get; set; }
[Required(ErrorMessage = "The license type field is required")]
[Display(Name = "License Type")]
public string LicenseType { get; set; }
[Display(Name="Department Name")]
public string DepartmentName { get; set; }
[Required(ErrorMessage = "The notify time field is required")]
[Display(Name = "Notify Time")]
public int NotifyTime { get; set; }
[Required(ErrorMessage = "The email field is required")]
[Display(Name = "Entry Created By")]
public string Email { get; set; }
public bool Active { get; set; }
}
PreDownload 방법 SoftwareLicense의 컨트롤러 : SoftwareLicense 컨트롤러에
public ActionResult PreDownload(int ID)
{
SoftwareLicense softwareLicense = db.SoftwareLicenses.Find(ID);
var fileNames = softwareLicense.LicenseFileName.Split(',');
foreach(string fileName in fileNames)
{
if(fileName.Length > 1)
{
Download(fileName, softwareLicense.SoftwareName);
}
}
SetUserInfo();
return View("Details", softwareLicense);
}
다운로드 방법 : 사람이 어떤 포인터 또는 솔루션이있는 경우
public FileResult Download(string fileName, string licenseName)
{
string returnName = licenseName + '-' + fileName;
if((fileName != "") || (fileName != " "))
{
return File("C:/Users/heathera/Desktop/Licenses/" + fileName, MediaTypeNames.Application.Octet, returnName);
}
else
{
return null;
}
}
나를 주시기 바랍니다 알다시피, 나는 하루나 이틀 동안 이것에 붙어있어 보일 수 없다. 그것을 알아 내라. 또한, 내 코드에 대한 지침이 있다면 항상 더 똑똑한 프로그래밍에 대해 배우려합니다.
미리 감사드립니다. Andrew.
정확하게 당신이 "작동하지 않는"무엇을 의미합니까? – stuartd
model-view-controller 태그는 패턴에 대한 질문입니다. ASP.NET-MVC 구현을위한 특정 태그가 있습니다. –
여러 파일을 반환하려면 컨테이너에 넣는 것이 가장 좋습니다 (예 : zip 파일 – stuartd