【问题标题】:How to Create ImageOptimize in mvc4(getting error)?如何在 mvc4 中创建 ImageOptimize(出现错误)?
【发布时间】:2012-10-05 14:37:34
【问题描述】:

大家好,我在为图像优化内容编写代码时正在 mvc4 中工作,显示我需要执行此操作的错误任何机构请帮助我解决这个问题,我收到此错误

这是我的代码:控制器

 public ActionResult Uploading(ImageModel model)
        {
            var uploadFolder = HostingEnvironment.MapPath("~/App_Data");
            uploadFolder = Path.Combine(uploadFolder, DateTime.Now.ToString("yyyy/MM/dd/hh/mm/ss/fff"));
            Directory.CreateDirectory(uploadFolder);
            var streamProvider = new PreserveFilenameMultipartFileStreamProvider(uploadFolder);

             Request.Content.ReadAsMultipartAsync(streamProvider).ContinueWith(t =>
            {
                foreach (var uploadedFile in Directory.GetFiles(uploadFolder))
                {

                    var medium = Path.Combine(uploadFolder, "medium-" + Path.GetFileName(uploadedFile));
                    var thumbnail = Path.Combine(uploadFolder, "thumb-" + Path.GetFileName(uploadedFile));
                    ImageTools.Resize(uploadedFile, thumbnail, 100, 100);
                    ImageTools.Resize(uploadedFile, medium, 50, 50);
                }
                return new HttpResponseMessage()
                {
                    Content = new StringContent("File uploaded.")

                };

            });
           return View("Upload", model);

        } 

这是我的索引页:

@using (Html.BeginForm("Uploading", "Upload", FormMethod.Post, new { enctype = "multipart/form-data" }))
 {
     <input type="file" name="ImageUploaded" id="btnUpload" multiple="multiple" accept="image/*"  />
 <button type="submit"  id="Upload">Upload</button>
     <br />
     //@Html.DisplayForModel(@ViewData["Time"]);        
     <label>@ViewData["Time"]</label>

 }

我在 Content 处遇到错误:HTTPRequestBase 不包含内容的定义

       Request.Content.ReadAsMultipartAsync(streamProvider).ContinueWith(t =>

谁能帮我解决问题提前谢谢

【问题讨论】:

    标签: image image-processing file-upload asp.net-mvc-4


    【解决方案1】:

    请在您的视图中使用以下行:

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

    因为是上传文件,所以需要定义上面这行代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-30
      • 2023-03-06
      • 2021-11-07
      • 2020-09-27
      • 2021-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多