2012-08-02 47 views
3

我在控制器中執行了此操作。

public ActionResult Upload(HttpPostedFileBase fileData) 
    { 
     //code for uploading goes here. 
     return View(); 
    } 

有沒有辦法使用$ .post或$ .Ajax訪問此操作? 在我的查看我有這些代碼。

<input type="file" name="fileData" id="fileData" multiple/> 
<button>Upload</button> 

首先,我嘗試使用此代碼

$("button").on("click",function(){ 
    $.post('@Url.Action' + $(".filedata").val(),function(data){ 
     console.log(data); 
    }); 
}); 

,但是當我試圖打破我的「上傳」行動來看,「FILEDATA」變量具有空值值。

我不知道是什麼問題。希望你能幫助我。

+0

你不能上傳文件這種方式使用Ajax。您必須使用'