我从处理图像上传的 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/