c# - 名称 'image' 在当前上下文中不存在

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

我从处理图像上传的 Controller 中的 HttpPost 属性收到编译错误。我已经搜索网络试图弄清楚我是否缺少某种命名空间,但是,唉,似乎没有任何地方有答案。这是我的 Controller 代码以及我的 View 代码。

       [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();
        }

我的 Controller 和 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" />
    }

最佳答案

代替

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

试试这个
imageModel.File.SaveAs(path + imageModel.File.FileName);

关于c# - 名称 'image' 在当前上下文中不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25278299/

相关文章:

html - 为什么不是 :last-of-type working on tumblr?

html - 更改 "comment"弹出窗口在 Facebook Like 按钮中的显示位置

javascript - 避免使用 jquery 对每个项目重复相同的代码

c# - 悬停事件错误触发

c# - Ameritrade API 流式 future - 符号命名约定?

javascript - Angular 无法从 Bootstrap 自定义复选框中删除焦点轮廓

razor - 如何使 MVC 4 Razor Html.Raw 在脚本标签内的 HTML 中赋值

asp.net-mvc-4 - 如何在操作中实现 Bootstrap link

c# - 如何获得类型的类

c# - 使用 C# 中的 PUT 请求将内容写入 Azure 存储上的文件