I get a webpage error message when I try to access a controller action in a MVC4 Web-API application with VS2010. I am trying to upload a small size (less than 1 MB) pdf document, create byte [] to switch to another service. However, I canโt get into either my regular controller or my api controller. My application works and all representations / partial / etc. show fine, except for this (page with the file upload form). This representation is strongly typed partial.
I tried using the method shown here: Download the MVC 4 Web API.NET 4 file , and also here: http://blogs.msdn.com/b/henrikn/archive/2012/03/01/file-upload-and- asp-net-web-api.aspx , and both of them do not work because my action attribute cannot find my action. I put api / Documents or Home / api / Documents, this will not work. So I gave up and returned to my beginform html helper, hoping that he would find it that way ... but that is not the case. Therefore, abandoning the fancy web-api stuff (I couldnโt get async to work), I thought that I would just go to the old school and submit the file through the form, but I get the same error. I also tried to recreate the page, configure my httphandlers, runtime settings, routes and apiroutes, and I am completely at a loss. Please, help!
My user interface:
My mistake: 
My form:
<div class="tab-pane" id="addDoc"> @using (Html.BeginForm("AddDocument", "Documents", FormMethod.Post, new { @class = "form-horizontal", @enctype = "multipart/form-data" })) { <label class="control-label" for="newFile">Upload : </label> <input name="newFile" type="file" /> <input type="submit" value="Submit" class="btn btn-success"/> } </div>
My API controller: I know this does not make sense, but I have a breakpoint to just see if it is even here, and it is not ...
[HttpPost] public AddDocumentResponse AddDocument(HttpPostedFileBase newFile) { AddDocumentResponse response = new AddDocumentResponse(); return response; }
My regular controller Action:
[HttpPost] public ActionResult AddDocument(HttpPostedFileBase newFile) { return View("DevNotes"); }
My WebApiConfig:
public static void Register(HttpConfiguration config) { config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "Home/api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); }
My RouteConfig:
public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); routes.MapRoute( name: "Default2", url: "Home/{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); }
Part of my webconfig:
<httpHandlers> <add path="*.less" verb="GET" type="dotless.Core.LessCssHttpHandler, dotless.Core" /> </httpHandlers> <httpRuntime executionTimeout="99009" maxRequestLength="2097151"/>