MVC 프로젝트에서 파일 업로드 페이지를 만들려고합니다. 우선 이걸 로컬로 관리하고 싶습니다. 내 질문은 : 1- 여기 내 컨트롤러와보기입니다. 이 코드를 작동시키기 위해해야 할 일이 있습니까? 나는 모델을 정의하거나 jquery를 사용하는 것을 의미한다. 파일이 업로드 될 때의 프로세스는 무엇인가? 나는이 문제를 디버깅 할 때Asp.Net MVC에서 파일 업로드 중
<input name="uploadFile" type="file" />
<input type="submit" value="Upload File" />
2, 그것은 컨트롤러에가는 결코 : 여기
[HttpPost]
public ActionResult FileUpload(HttpPostedFileBase uploadFile)
{
if (uploadFile.ContentLength > 0)
{
string filePath = Path.Combine(HttpContext.Server.MapPath("C:/Users/marti/../PhotoGallery/myimages"),
Path.GetFileName(uploadFile.FileName));
uploadFile.SaveAs(filePath);
}
return View();
}
은보기입니다.
@model ImageModel
@{
ViewBag.Title = "New Image";
}
<div class="content-form-container width-half">
<form id='PropertiesForm' action='@Url.Action(ImageController.Actions.Add, ImageController.Name)' method='post' enctype='multipart/form-data' class='content-form'>
@Html.Partial("ImageName")
<fieldset class='content-form-1field'>
<div class='legend'>
file to upload
</div>
@Html.LabelledFileInput(ImageView.FileName, string.Empty)
</fieldset>
<div class='buttons'>
@Html.Button("button-submit", "submit")
</div>
</form>
</div>
@section script{
@Html.JavascriptInclude("~/js/image/new.min.js")
}
을 그리고 여기 내 컨트롤러 코드는 다음과 같습니다 :
확실하지 않습니다. 작동하지 않는 것은 무엇입니까? 또는 파일 업로드 진행률을 원하십니까? – Craig
게시물 요청을 통해 제출하고 컨트롤러에'FormCollection collection'을 허용하려면 Html 폼'
예 파일 업로드 진행이 필요했습니다. – Mgnfcnt