HttpPostedFileBase为null mvc

时间:2014-06-16 19:39:27

标签: asp.net-mvc image-uploading httppostedfilebase

我一直试图找出为什么我的HttpPostedFileBase返回null。我查看了其他答案,并遵循了一些关于如何上传图像的教程。问题是我仍然只是从HttpPostedFileBase和Request.Files获取null。有什么我想念的吗?

我的控制器

    [HttpPost]
    public ActionResult Save(HttpPostedFileBase PreviewImageFile)
    {

        //some code//

        if (PreviewImageFile.ContentLength > 0)
        {
            try
            {
                var uploadedImage = new Bitmap(PreviewImageFile.InputStream);
                var width = 368;
                var height = 305;
                var uploadedImageThumb = ImageHelper.CreateThumbnail(uploadedImage, width, height);

                uploadedImageThumb.Save("/path" + id + ".png", ImageFormat.Png);
                uploadedImageThumb.Dispose();
                uploadedImage.Dispose();

            }
            catch
            {

            }
        }

        //some code here//

        return Json(new { success = true });
    }

我的表格来自视图

                <% using (Html.BeginForm("Save", "SaveThemes", FormMethod.Post, new { enctype = "multipart/form-data", @id = "TestForm" }))
                   {  %>

                        <label for="PreviewImageFile">Perview Image</label>
                        <input type="file" id="PreviewImageFile" name="PreviewImageFile" size="40" value="" />


                //some code here//
                <button type="submit" >save</button>
                <% } %>

0 个答案:

没有答案