2011-09-27 28 views
9

我希望能夠以一種形式發佈多個文件。我想將這些文件作爲文件數組傳遞。例如,我想這樣做。如何發佈ASP.NET MVC 3中的文件數組?

<input type="file" name="files[0]" /> 
<input type="file" name="files[1]" /> 
<input type="file" name="files[2]" /> 

然後,我想能夠接收這些文件作爲控制器中的數組。我試過這個。

public ActionResult AddPart(HttpPostedFileBase[] files) 

但這不起作用。我用Google搜索了它,但我能找到的只是上傳一個文件的例子。有誰知道如何使用MVC3 C#來做到這一點。

回答

4

如果您不想只上傳一個文件,則需要在表單中使用enctype="multipart/form-data"

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

和控制器:

[HttpPost] 
public ActionResult AddPart(IEnumerable<HttpPostedFileBase> files) 

所有其它部件就可以了。

+0

還有別的東西可能會丟失,因爲您作爲解決方案發布的內容似乎不起作用。 – spartacus

+1

沒關係,沒有工作。謝謝(你的)信息! – spartacus

相關問題