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パラメータが最初に到着から私はそれをViewDataディクショナリに渡し、それをビューの隠しフィールドとしてレンダリングする必要がありますか? –
あなたはcontroller/action/idのデフォルトルートを使用していますか?クエリ文字列の代わりに、ルートのid部分として渡すことができます。あなたのgetは "public ActionResult Upload(string id)"、 "httppost"は "public actionresult(httppostedfilebase file、string id)"になります。 –