Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC 3 Web API Routing Not Working
    text
    copied!<p>I'm fighting issues with routing in an MVC 3 Web API. It seems like it should be pretty simple, but I'm not making any headway.</p> <p>My error is:</p> <pre><code> &lt;Error&gt; &lt;Message&gt;The request is invalid.&lt;/Message&gt; &lt;MessageDetail&gt; The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'Boolean NewViolationsPublished(Int32)' in 'BPA.API.Controllers.CacheManagementController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. &lt;/MessageDetail&gt; &lt;/Error&gt; </code></pre> <p>My RegisterRoutes is such:</p> <pre><code>public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapHttpRoute( name: "NukeAllItemsFromCache", routeTemplate: "api/CacheManagement/NukeAllItemsFromCache"); routes.MapHttpRoute( name: "ControllerAndAction", routeTemplate: "api/{controller}/{action}" ); routes.MapHttpRoute( name: "ControllerAndActionAndId", routeTemplate: "api/{controller}/{action}/{id}", defaults: new { id = RouteParameter.Optional, action = "Get" }, constraints: new { id = @"^\d+$" } // Only integers ); routes.MapHttpRoute( name: "ControllerAndId", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional }, constraints: new { id = @"^\d+$" } // Only integers ); } </code></pre> <p>And my controller is (i took out the code for ease of reading):</p> <pre><code> public class CacheManagementController : ApiController { public CacheManagementController() [HttpGet] public bool NewViolationsPublished(int id) [HttpGet] public bool IsCached(CachedItemLabels label, int clientId) [HttpGet] public void RemoveItemFromCache(int clientId, CachedItemLabels cacheLabel, string test) [HttpGet] public string NukeAllItemsFromCache() } </code></pre> <p><strong>I get the error when I try to call:</strong></p> <pre><code>http://localhost/api/CacheManagement/NukeAllItemsFromCache </code></pre> <p>TIA</p>
 

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