선택한 파일을 asp mvc4의 폴더에 업로드하는 기능이 있습니다. 보기 페이지의 코드는aps mvc의 json을 사용하여 이미지 업로드
<form id="form1" method="post" enctype="multipart/form-data" action="EmployeeDetails/Upload">
<input type='file' id="imgInp" accept="image/jpeg"/>
<p>
<input type="submit" value="Upload" class="btn"/>
</p>
</form>
입니다 그리고 컨트롤러 코드 대신 내가 JSON으로 컨트롤러에 뷰에서 이미지를 보내려면이의
[HttpPost]
public ActionResult Upload(HttpPostedFileBase imgInp)
{
if (imgInp != null && imgInp.ContentLength > 0)
{
// extract only the fielname
var fileName = Path.GetFileName(imgInp.FileName);
// store the file inside ~/App_Data/uploads folder
var path = Path.Combine(Server.MapPath("~/images/Profile"), fileName);
imgInp.SaveAs(path);
}
return view("Index");
}
입니다. 또는보기 페이지를 새로 고치지 않고 이미지를 업로드 할 수있는 다른 방법이 있습니까? 당신은 아약스 사용하여 양식을 보낼 수 있습니다
가있어. 양식에 다른 내용이 있으면 작동합니까? 업로드 된 이미지를 양식 자체에 표시하려고합니다. – BPX
예, 작동합니다 ... 전체 양식을 보낼 수 있습니다. 단지'FormData'에서 데이터를 추가하면 작동합니다. – Nilesh
업로드하기 전에 파일 이름을 변경할 수 있습니까? 어떻게 업로드 할 특정 경로를 지정할 수 있습니까? – BPX