2015-09-25 143 views
0

我正在嘗試使用jQuery提交表單。該表單包含一個文件上傳輸入,我用this SO method僞裝,並自動使用this SO method提交。當我檢查我的控制器中的_upload的參數時,type有一個值,但file爲空。提交包含類型文件輸入的jQuery表單

我哪裏錯了?

查看:

@using (Html.BeginForm("_upload", "Config", null, FormMethod.Post, new { @id = "form_" + Model.imageType })) 
    { 
     <label> 
      <input id="[email protected]" type="file" name="file" required /> 
     </label> 
      @Html.Hidden("type",Model.imageType) 
    } 
.... 
<script> 
    $(function() { 
     $('#[email protected]').change(function() { 
      $('#[email protected]').submit(); 
     }) 
    }) 
</script> 

控制器

[HttpPost] 
    public void _upload(HttpPostedFileBase file, string imageType) 
    { 
     //dostuff 
    } 

回答

0

更改您的剃鬚刀/形式是這樣的:

@using (Html.BeginForm("_upload", "Config", FormMethod.Post, new { enctype = "multipart/form-data" })){} 
+1

感謝,這是我錯過了什麼! – tallpaul

相關問題