久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<tfoot id='YDYro'></tfoot>

<i id='YDYro'><tr id='YDYro'><dt id='YDYro'><q id='YDYro'><span id='YDYro'><b id='YDYro'><form id='YDYro'><ins id='YDYro'></ins><ul id='YDYro'></ul><sub id='YDYro'></sub></form><legend id='YDYro'></legend><bdo id='YDYro'><pre id='YDYro'><center id='YDYro'></center></pre></bdo></b><th id='YDYro'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='YDYro'><tfoot id='YDYro'></tfoot><dl id='YDYro'><fieldset id='YDYro'></fieldset></dl></div>
    <bdo id='YDYro'></bdo><ul id='YDYro'></ul>

      1. <legend id='YDYro'><style id='YDYro'><dir id='YDYro'><q id='YDYro'></q></dir></style></legend>

        <small id='YDYro'></small><noframes id='YDYro'>

        使用 MVC 3 上傳文件

        Uploading files with MVC 3(使用 MVC 3 上傳文件)

        <small id='qgtuW'></small><noframes id='qgtuW'>

        <legend id='qgtuW'><style id='qgtuW'><dir id='qgtuW'><q id='qgtuW'></q></dir></style></legend>
        <i id='qgtuW'><tr id='qgtuW'><dt id='qgtuW'><q id='qgtuW'><span id='qgtuW'><b id='qgtuW'><form id='qgtuW'><ins id='qgtuW'></ins><ul id='qgtuW'></ul><sub id='qgtuW'></sub></form><legend id='qgtuW'></legend><bdo id='qgtuW'><pre id='qgtuW'><center id='qgtuW'></center></pre></bdo></b><th id='qgtuW'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='qgtuW'><tfoot id='qgtuW'></tfoot><dl id='qgtuW'><fieldset id='qgtuW'></fieldset></dl></div>

          <bdo id='qgtuW'></bdo><ul id='qgtuW'></ul>
            <tbody id='qgtuW'></tbody>

              • <tfoot id='qgtuW'></tfoot>

                  本文介紹了使用 MVC 3 上傳文件的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  離開 mvc3,我越來越瘦了.我的控制器中有以下代碼

                  I'm growing thin learving mvc3. I have the following code in my controller

                      [HttpPost]
                      public ActionResult Accreditation(Accreditation accreditation)
                      {
                          if (ModelState.IsValid)
                          {
                              var fileUpload = Request.Files[0];
                              var uploadPath = Server.MapPath("~/App_Data/uploads");
                  
                              using (var fs = new FileStream(Path.Combine(uploadPath, accreditation.PressCard.ToString()), FileMode.Create))
                              {
                                  var buffer = new byte[fileUpload.InputStream.Length];
                                  fileUpload.InputStream.Read(buffer, 0, buffer.Length);
                  
                                  fs.Write(buffer, 0, buffer.Length);
                              }
                  
                              context.Accreditations.Add(accreditation);
                              context.SaveChanges();
                  
                              return RedirectToAction("Index");  
                          }
                  
                  
                             ViewBag.PossibleNationalities = context.Nationalities;
                              ViewBag.PossibleNchis = context.Nchis;
                              ViewBag.PossibleMedia = context.Media;
                              ViewBag.PossibleEmploymentStatus = context.EmploymentStatus;
                              return View(accreditation);
                  
                  
                  
                      }
                  }
                  

                  這是視圖:

                  @using (Html.BeginForm("Accreditation", "Home", new { enctype = "multipart/form-data" },    FormMethod.Post))
                  {
                     @Html.ValidationSummary(true)
                  .............
                  .............
                  
                  <div class="editor-field">
                         <input type="file" name="PressCard" id="PressCard" data-val-required="Press card is required" data-val="true"/>
                           @Html.ValidationMessageFor(model => model.PressCard)
                      </div>
                  
                      <div class="editor-label">
                          @Html.LabelFor(model => model.Passport)
                      </div>
                      <div class="editor-field">
                         <input type="file" name="Passport" id="Passport" data-val-required="ID/Passport is required" data-val="true"/>
                          @Html.ValidationMessageFor(model => model.Passport)
                      </div>
                  

                  ..................

                  ....... ........

                  當我嘗試上傳時,我收到以下錯誤消息:

                  When I try to upload, i get the following error message:

                  異常詳細信息:System.ArgumentOutOfRangeException:索引超出范圍.必須是非負數且小于集合的大小.參數名稱:索引

                  Exception Details: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

                  任何人都有指向正確方向的指針嗎?

                  Any one out there with a pointer to the right direction?

                  抱歉耽擱了.這是新代碼

                  sorry for delay. Here's the new code

                  [HttpPost]
                  public ActionResult Accreditation(Accreditation accreditation, HttpPostedFileBase Passport)
                      {
                          if (ModelState.IsValid)
                          {
                              var uploadPath = Server.MapPath("~/App_Data/uploads");
                  
                              using (var fs = new FileStream(Path.Combine(uploadPath, accreditation.PressCard.ToString()), FileMode.Create))
                              {
                                  var buffer = new byte[Passport.InputStream.Length];
                                  Passport.InputStream.Read(buffer, 0, buffer.Length);
                  
                                  fs.Write(buffer, 0, buffer.Length);
                              }
                  
                              context.Accreditations.Add(accreditation);
                              context.SaveChanges();
                  
                              return RedirectToAction("Index");  
                          }
                  
                  
                             ViewBag.PossibleNationalities = context.Nationalities;
                              ViewBag.PossibleNchis = context.Nchis;
                              ViewBag.PossibleMedia = context.Media;
                              ViewBag.PossibleEmploymentStatus = context.EmploymentStatus;
                              return View(accreditation);
                  
                  
                  
                      }
                  }
                  

                  推薦答案

                  真的是在上傳數據嗎?我建議你使用這種方式.創建一個類型為 HttpPostedFileBase 的參數,該參數與輸入字段同名,并測試其內容長度屬性.

                  Are really uploading data? I'd suggest you use this way. Create a parameter of type HttpPostedFileBase with the same name as the input field and test for its content length property.

                  檢查此鏈接將是您繼續前進的最快方式.

                  Checking this link will the fastest way for you to move on.

                  MVC 3 文件上傳和模型綁定

                  這篇關于使用 MVC 3 上傳文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  What are good algorithms for vehicle license plate detection?(車牌檢測有哪些好的算法?)
                  onClick event for Image in Unity(Unity中圖像的onClick事件)
                  Running Total C#(運行總 C#)
                  Deleting a directory when clicked on a hyperlink with JAvascript.ASP.NET C#(單擊帶有 JAvascript.ASP.NET C# 的超鏈接時刪除目錄)
                  asp.net listview highlight row on click(asp.net listview 在單擊時突出顯示行)
                  Calling A Button OnClick from a function(從函數調用按鈕 OnClick)
                  1. <i id='cY7bE'><tr id='cY7bE'><dt id='cY7bE'><q id='cY7bE'><span id='cY7bE'><b id='cY7bE'><form id='cY7bE'><ins id='cY7bE'></ins><ul id='cY7bE'></ul><sub id='cY7bE'></sub></form><legend id='cY7bE'></legend><bdo id='cY7bE'><pre id='cY7bE'><center id='cY7bE'></center></pre></bdo></b><th id='cY7bE'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='cY7bE'><tfoot id='cY7bE'></tfoot><dl id='cY7bE'><fieldset id='cY7bE'></fieldset></dl></div>
                  2. <small id='cY7bE'></small><noframes id='cY7bE'>

                      <tbody id='cY7bE'></tbody>

                      <bdo id='cY7bE'></bdo><ul id='cY7bE'></ul>
                      <legend id='cY7bE'><style id='cY7bE'><dir id='cY7bE'><q id='cY7bE'></q></dir></style></legend>
                    • <tfoot id='cY7bE'></tfoot>

                          • 主站蜘蛛池模板: 久久中文字幕在线 | 久久久免费少妇高潮毛片 | 中文字幕成人 | 91电影在线播放 | 视频在线观看亚洲 | 日本亚洲一区 | 欧美不卡一区二区 | 久久精品 | 91精品久久久久久久久中文字幕 | 亚洲视频免费观看 | 米奇狠狠鲁 | 国产精品视频免费观看 | 国产无套一区二区三区久久 | 欧美精品网站 | 欧美三级在线 | 欧美大片黄| 爱高潮www亚洲精品 中文字幕免费视频 | 国产精品www | 精品久久久久久久久久久久 | 在线观看亚洲一区二区 | 亚洲国产伊人 | 国产欧美在线视频 | 巨大黑人极品videos精品 | 日韩伦理电影免费在线观看 | 国产 日韩 欧美 在线 | 521av网站| 免费中文字幕 | 久久国内精品 | 成人精品一区二区三区中文字幕 | 欧美日韩不卡合集视频 | 黄一区二区三区 | 国产伦精品一区二区三区照片91 | 国产精品视频在线免费观看 | 日韩欧美专区 | 一级片在线观看 | 久久91精品 | 精品国产久 | aaaaa毛片| 午夜日韩精品 | 亚洲欧美视频 | 久久毛片 |