2011-01-30 7 views

답변

1

HTML 파일 업로드 ASP MVC 3

모델 : (FileExtensionsAttribute가 MvcFutures에서 사용할 수 있는지 주 그것은 파일 확장자 클라이언트 측과 서버 측 유효성을 검사합니다..)

public class ViewModel 
{ 
    [Required, Microsoft.Web.Mvc.FileExtensions(Extensions = "csv", ErrorMessage = "Specify a CSV file. (Comma-separated values)")] 
    public HttpPostedFileBase File { get; set; } 
} 

HTML보기 :

컨트롤러 액션 :

[HttpPost] 
public ActionResult Action(ViewModel model) 
{ 
    if (ModelState.IsValid) 
    { 
     // Use your file here 
     using (MemoryStream memoryStream = new MemoryStream()) 
     { 
      model.File.InputStream.CopyTo(memoryStream); 
     } 
    } 
} 
관련 문제