I am new to ASP.NET MVC RAZOR and I am trying to implement a File Upload to my page. I found many questions concerning this topic but I have an error and I can´t figure out why. This is my form in my view:
@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" />
}
And this is my Controller:
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"); ;
}
}
}
When I run my page I get an error, which says: "Ressource not found: "/Upload". Where is my mistake? Sorry, I know I am a beginner in ASP.NET but I read many tutorials and just want this to work. Thanks a lot.