I'm having the weirdest problem with file uploads in ASP.NET MVC 3. When I start a new project with the default project template (Internet application) with Razor and add the following to /views/home/index.cshtml
<form action="/Home/Index" method="post" enctype="multipart/form-data">
<input type="file" name="upfile" />
<input type="submit" value="post" />
</form>
the upload fails (firebug shows status 'Aborted') whenever I try to upload a file. Some extra info:
- Windows 7 / 64bit
- Cassini
- VS SP1
- It happens in both Firebug 6.0.2 and IE8
Controller code:
public class HomeController : Controller {
public ActionResult Index() {
ViewBag.Message = "Welcome to ASP.NET MVC!";
return View();
}
public ActionResult About() {
return View();
}
}
I've been debugging this for a bit and already found out the following:
- it only happens for files > ~120kb
- if I add a target Action with attribute [HttpPost] upload succeeds
- if I debug using fiddler (proxy) upload succeed
- if I use aspx and add the same code, upload succeeds
- for aspx/razor, all file are identical, except for (of course) the files in /Views but not /Views/Web.config
Has anyone else experienced this problem, and what is causing it?
update: I know I should use a separate action and mark it with HttpPost, that's not why I'm asking this question. I'm looking for the reason why this doesn't work, not how to solve it.