0
MVC 응용 프로그램에서 GET 및 POST 동작을 사용하여 업로드 뷰가 있습니다.HttpPostedFileBase 개체와 함께 추가 매개 변수를 전달하십시오.
질문은 어떻게하면 HttpPostedFileBase 개체 (예 : 일부 ID)와 함께 POST 동작에 여분의 데이터를 전달할 수 있습니까?
MVC 응용 프로그램에서 GET 및 POST 동작을 사용하여 업로드 뷰가 있습니다.HttpPostedFileBase 개체와 함께 추가 매개 변수를 전달하십시오.
질문은 어떻게하면 HttpPostedFileBase 개체 (예 : 일부 ID)와 함께 POST 동작에 여분의 데이터를 전달할 수 있습니까?
당신은 추가 매개 변수로 전달
HTML :
<form action="" method="post" enctype="multipart/form-data">
<input type='text' id='txtId' name='id'/>
<input type="file" name="file" id="file" />
<input type="submit" />
</form>
컨트롤러 :
[HttpPost]
public ActionResult Upload(HttpPostedFileBase file, string id) {
if (file.ContentLength > 0) {
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
file.SaveAs(path);
}
return RedirectToAction("Index");
}
감사 Ryand, id 매개 변수는 원래 도착 ~로부터 QueryString으로 GET 작업을 ViewData 사전에 전달하고보기의 숨겨진 필드로 렌더링해야합니까? –
컨트롤러/액션/id의 기본 경로를 사용하고 있습니까? 쿼리 문자열 대신 경로의 ID 부분으로 전달할 수 있습니다. 따라서 당신의 get은 "public ActionResult Upload (string id)"가 될 것이고 [httppost]는 "public actionresult (httppostedfilebase file, string id) –