How to pass multiple params to a HttpGet method inside of a C# ApiController?

I have this:

public class RuleController : ApiController
    private readonly IRuleManager _ruleManager;

    // GET: api/Rule/guid
    public IHttpActionResult GetRule(Guid id)
        var rules = _ruleManager.GetRulesById(id);
        return Ok(rules);

    public async Task<IHttpActionResult> GetRuleNew(string locale, string pno, string modelYear)
      // do cool stuff with my params


my route config:

        config.Routes.MapHttpRoute("DefaultApiWithId", "Api/{controller}/{id}", new { id = RouteParameter.Optional }, new { id = @"\d+" });
        config.Routes.MapHttpRoute("DefaultApiWithAction", "Api/{controller}/{action}");
        config.Routes.MapHttpRoute("DefaultApiGet", "Api/{controller}", new { action = "Get" }, new { httpMethod = new HttpMethodConstraint(HttpMethod.Get) });
        config.Routes.MapHttpRoute("DefaultApiPost", "Api/{controller}", new { action = "Post" }, new { httpMethod = new HttpMethodConstraint(HttpMethod.Post) });
        name: "ActionApi",
        routeTemplate: "api/{controller}/{action}/{id}",
        defaults: new { id = RouteParameter.Optional }

calling my route:


I get:

"Message": "No HTTP resource was found that matches the request URI
"MessageDetail": "No action was found on the controller ‘Rule’ that
matches the request."

What am I missing?

>Solution :

Have you tried using this instead ?


Basically just use a & (instead of a ?) for the second and subsequent query parameters…

Leave a Reply