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

        <legend id='dUkCY'><style id='dUkCY'><dir id='dUkCY'><q id='dUkCY'></q></dir></style></legend>
        <tfoot id='dUkCY'></tfoot>

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

        • <bdo id='dUkCY'></bdo><ul id='dUkCY'></ul>
      2. ASP.NET MVC 上傳圖片

        ASP.NET MVC upload image(ASP.NET MVC 上傳圖片)
          <tbody id='HDTYn'></tbody>
        <legend id='HDTYn'><style id='HDTYn'><dir id='HDTYn'><q id='HDTYn'></q></dir></style></legend>
            • <bdo id='HDTYn'></bdo><ul id='HDTYn'></ul>
                <i id='HDTYn'><tr id='HDTYn'><dt id='HDTYn'><q id='HDTYn'><span id='HDTYn'><b id='HDTYn'><form id='HDTYn'><ins id='HDTYn'></ins><ul id='HDTYn'></ul><sub id='HDTYn'></sub></form><legend id='HDTYn'></legend><bdo id='HDTYn'><pre id='HDTYn'><center id='HDTYn'></center></pre></bdo></b><th id='HDTYn'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='HDTYn'><tfoot id='HDTYn'></tfoot><dl id='HDTYn'><fieldset id='HDTYn'></fieldset></dl></div>

                1. <small id='HDTYn'></small><noframes id='HDTYn'>

                  <tfoot id='HDTYn'></tfoot>
                  本文介紹了ASP.NET MVC 上傳圖片的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我找到了一些代碼來執行此操作并嘗試將其實現到我的項目中,但到目前為止它一直沒有成功.我沒有收到任何錯誤,但我沒有看到任何圖像存儲在 Visual Studio 內的圖像目錄中.

                  I've found some code to do this and tried to implement it into my project, but so far it has been unsuccessful. I don't get any errors, but I don't see any images being stored in my images directory inside visual studio.

                  查看:

                    @using (Html.BeginForm())
                  {
                      <span>Please enter your story here:</span>
                      <textarea id="testimonial" name="testimonial"></textarea>
                      <button type="submit">Submit</button>
                      <input type="file" name="file" />
                  }
                  

                  控制器:

                  [HttpPost]
                      public ActionResult Create(Testimonials testimonials)
                      {
                          if (Request.Files.Count > 0)
                          {
                              var file = Request.Files[0];
                  
                              if (file != null && file.ContentLength > 0)
                              {
                                  var fileName = Path.GetFileName(file.FileName);
                                  var path = Path.Combine(Server.MapPath("~/Images/"), fileName);
                                  file.SaveAs(path);
                              }
                          }
                  
                  
                          TestimonialsContext testContext = new TestimonialsContext();
                          testContext.testimonialContext.Add(testimonials);
                          testContext.SaveChanges();
                          return RedirectToAction("Index");
                      }
                  

                  if 塊下方的部分工作正常.這只是將文本區域的內容保存到數據庫中.有什么想法嗎?我需要對我的模型進行任何更改嗎?

                  The part below the if block works fine. That just saves the content of a textarea to the database. Any thoughts? Do I need to make any changes to my model?

                  型號:

                  [Table("Testimonials")]
                  public class Testimonials
                  {
                      public int Id { get; set; }
                      public string Testimonial { get; set; }
                  }
                  

                  上下文類:

                  public class TestimonialsContext:DbContext
                  {
                      public DbSet<Testimonials> testimonialContext { get; set; }
                  }
                  

                  推薦答案

                  您的文件未發布,因為您在表單上沒有必要的 enctype 屬性.更改要使用的視圖

                  Your file is not being posted because you do not have the necessary enctype attribute on the form. Change the view to use

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

                  您現在將獲取文件并保存它,但與您的 Testimonials 對象沒有關系,因此您無法檢索它.您需要在 Testimonials 表中添加其他字段來存儲文件屬性(如果 Testimonials 可以有多個圖像,則需要一個單獨的表).我還建議您使用唯一標識符將文件保存到您的服務器(例如,一個 Guid 以防止在 2 個用戶上傳同名文件時意外覆蓋).您修改后的模型可能是

                  You will now get the file and save it, but there is no relationship to your Testimonials object so you cannot retrieve it. You will need to add additional fields in your Testimonials table to store the file properties (or a separate table if a Testimonials can have multiple images). I also recommend you save the file to your server with a unique identifier (e.g. a Guid to prevent accidental overwriting if 2 users upload files with the same name). You revised model might be

                  public class Testimonials
                  {
                      public int Id { get; set; }
                      public string Testimonial { get; set; }
                      public string ImagePath { get; set; }
                      public string ImageDisplayName { get; set; }
                  }
                  

                  我還建議對包含上述屬性的視圖使用視圖模型以及 public HttpPostedFileBase Image { get;放;} 以便您可以強綁定到模型并添加驗證屬性(例如 [FileSize] 屬性,假設您不希望允許用戶上傳 2GB 文件).您的控制器方法將是

                  I would also recommend using a view model for the view that includes the above properties plus public HttpPostedFileBase Image { get; set; } so that you can strongly bind to the model and add validation attributes (for example a [FileSize] attribute assuming you do not want to allow users to upload 2GB files). Your controller method would then be

                  [HttpPost]
                  public ActionResult Create(TestimonialVM model)
                  {
                      // ModelState.IsValid check omitted
                      Testimonials testimonials = new Testimonials();
                      // map view model properties to the data model
                      ....
                      if (model.Image != null && model.Image.ContentLength > 0)
                      {
                          string displayName = model.Image.FileName;
                          string fileExtension = Path.GetExtension(displayName);
                          string fileName = string.Format("{0}.{1}", Guid.NewGuid(), fileExtension)
                          string path = Path.Combine(Server.MapPath("~/Images/"), fileName)
                          model.Image.SaveAs(path);
                          // Update data model
                          testimonials.ImagePath = path;
                          testimonials.ImageDisplayName = displayName;
                      }
                      TestimonialsContext testContext = new TestimonialsContext();
                      testContext.testimonialContext.Add(testimonials);
                      testContext.SaveChanges();
                      return RedirectToAction("Index");
                  }
                  

                  這篇關于ASP.NET MVC 上傳圖片的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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)

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

                  1. <tfoot id='IX9q1'></tfoot>

                      • <bdo id='IX9q1'></bdo><ul id='IX9q1'></ul>

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

                        <legend id='IX9q1'><style id='IX9q1'><dir id='IX9q1'><q id='IX9q1'></q></dir></style></legend>
                              <tbody id='IX9q1'></tbody>
                            主站蜘蛛池模板: 天天拍天天操 | 深夜福利影院 | 久久精品欧美一区二区三区麻豆 | 久久人人网 | 欧美全黄 | 91高清在线观看 | 欧美日韩国产精品一区二区 | 日韩欧美国产精品一区二区三区 | 国产精品一区二区精品 | 国产精品99久久免费观看 | 久草视频网站 | 欧美黑人巨大videos精品 | 天天操人人干 | 亚洲成av人片在线观看无码 | 日韩午夜电影在线观看 | 久久久高清 | 国内精品视频在线观看 | 在线观看三级av | 成人精品一区二区三区 | 国产一级片av | 国产精品久久久久久中文字 | 国产一伦一伦一伦 | 亚洲精品久久久久久国产精华液 | 在线欧美视频 | 中文字幕国产高清 | 成人在线视频免费观看 | 精品91av| 自拍在线| 伊人网综合 | 黑人性hd| 日本视频在线播放 | 精久久久| 久久精品国产清自在天天线 | 欧美成人一级 | 99久久久99久久国产片鸭王 | 精品国产91亚洲一区二区三区www | 欧美日韩亚洲视频 | 亚洲在线久久 | www精品美女久久久tv | 91污在线 | 欧美99|