【发布时间】:2013-11-11 15:16:56
【问题描述】:
我是 ASP.NET MVC RAZOR 的新手,我正在尝试将文件上传到我的页面。我发现了很多关于这个主题的问题,但我有一个错误,我不知道为什么。 这是我认为的表格:
@using (Html.BeginForm("Upload", "Upload", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<input type="file" name="file" />
<input type="submit" name="Submit" id="Submit" value="Upload" />
}
这是我的控制器:
namespace Upload.Controllers
{
public class UploadController : Controller
{
//
// GET: /Upload/
public ActionResult Upload()
{
return View();
}
[HttpPost]
public ActionResult Upload(HttpPostedFileBase file)
{
if (file != null && file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine("C:\\temp\\", fileName);
file.SaveAs(path);
}
return RedirectToAction("Index"); ;
}
}
}
当我运行我的页面时,我得到一个错误,它说: “未找到资源:“/上传”。 我的错误在哪里?抱歉,我知道我是 ASP.NET 的初学者,但我阅读了很多教程,只是希望它能够正常工作。 非常感谢。
【问题讨论】:
标签: .net asp.net-mvc razor