Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The URL your posting to is finding its way to your controller class because your default route mappings are mapping "/api/Files/" to the FilesController. However, your URI doesn't identify an "action", e.g. "/api/Files/Post".</p> <p>BTW, the default routes in an ASP.NET MVC application are "/{controller}/{action}" and usually have defaults "controller=Default" and "action=Index". So, by default, "/api/Files" would be looking for an action method named "Index", but your FilesController has no such method.</p> <p>Short answers:</p> <ol> <li>Add "/Post" to the end of the URL you're posting to</li> <li>Or, rename your "Post()" action method to "Index()"</li> </ol> <p>Long answer:</p> <ol> <li>Look in Global.asax.cs where the routes are set up and consider setting up some very custom routes so you can have your URIs look however you want independent of how you organize your controller classes and action methods.</li> </ol> <p>Now that you've posted your Global.asax.cs, let's examine the one route template you have:</p> <pre><code>"{controller}/{filename}" </code></pre> <p>You're telling MVC that when you have a URL that looks like "/something/somethingelse" to take the "something" and use that as the controller name, and the "somethingelse" as the filename. Nothing in your route identifies <em>which</em> action to invoke.</p> <p>Now that's OK if you don't want any other actions to be invoked. In that case, you can hard-code the action "Post" in the defaults for the route:</p> <pre><code>defaults: new { filename = RouteParameter.Optional, action = "Post" } </code></pre> <p>If you want to be able to invoke the other action methods you have (e.g. Put, Delete, etc.), then you can modify your URL patterns (and calling URL) to include "action":</p> <pre><code>"{controller}/{action}/{filename}" // E.g. url: "/Files/Post/myfilename.txt" </code></pre> <p>Or, maybe you really want everything to always go through the FilesController in which case you can set the controller in the defaults and have the route template just expect the action and filename (e.g. .../Post/myfilename.txt):</p> <pre><code> routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "{action}/{filename}", defaults: new { filename = RouteParameter.Optional, controller = "Files"} ); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload