2012-08-02 71 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。您必须使用'