2011-11-03 189 views
0

請告訴我,我的代碼有什麼問題。當我試圖把被公佈文件中的控制器,它拋出指數超出範圍的異常:上傳文件崩潰

<% using (Html.BeginForm("Upload", "Home", new { enctype = "mulitipart/form-data" })) 
    {%> 
    <%: Html.ValidationSummary(true) %> 

    <fieldset> 
     <legend>Fields</legend> 

     <br> 
     <input type="file" name="file"/> 
     <p> 
      <input type="submit" value="Create" /> 
     </p> 
    </fieldset> 

<% } %> 

控制器的方法:

public ActionResult Upload(){ 
var r = Request.Files[0]; //here i got an exception  
     byte[] b=new byte[r.ContentLength]; 
     r.InputStream.Read(b, 0, r.ContentLength); 
     ................................... 
+0

與'enctype'和'Request.Files'混淆?哎喲。您需要取消學習Web窗體並學習一些MVC。 – bzlm

+0

你有單獨的GET和POST操作嗎? GET應該顯示您的視圖,並且您應該將檢查Request.Files屬性的代碼放入POST操作中。 – Dismissile

回答

1

看起來它可能只是一個拼寫錯誤......,你必須mulitipart/form-data應該是multipart/form-data ...你有一個額外的「我」在那裏。

+0

不幸的是,沒有 – xalz