名称'图像'在当前上下文中不存在

时间:2014-08-13 04:51:24

标签: c# html5 razor namespaces asp.net-mvc-5

我的控制器中的HttpPost属性收到编译错误,处理图像上传。我已经在网上搜索,试图找出我是否缺少某种命名空间,但是,唉,似乎没有答案。这是我的控制器代码以及我的视图代码。

       [HttpPost]
        public ActionResult PhotoUpload(artisan.Models.UploadImageModel imageModel)
        {
            string path = @"D:\Temp\";

            if (ModelState.IsValid)
            {
                if (imageModel != null && imageModel.File != null)
                    image.SaveAs(path + imageModel.File.FileName);

                return RedirectToAction("Profile");
            }

            return View();
        }

我的控制器和视图位于各自文件夹中的单独文件中。

@using (Html.BeginForm("PhotoUpload", "Profile", FormMethod.Post, new { enctype = "multipart/form-data" }))
    {
        <label for="image">Upload Profile Image:</label>
        <input type="image" name="profilephoto" id="profilephoto" style="width: 100%;" />
        <input type="submit" value="Upload" class="submit" />
    }

1 个答案:

答案 0 :(得分:1)

而不是

image.SaveAs(path + imageModel.File.FileName);

试试这个

imageModel.File.SaveAs(path + imageModel.File.FileName);