WebAPI No action was found on the controller

I got an error - No action was found on the controller 'Action' that matches the request.

The url is http://localhost:37331/api/action/FindByModule/1.

The routing I used is

config.Routes.MapHttpRoute(
    name: "DefaultApi",
    routeTemplate: "api/{controller}/{action}/{id}",
    defaults: new { id = RouteParameter.Optional }
);

Controller:

public class ActionController : ApiController
{
    private IActionRepository repository = null;

    [HttpGet]
    [ActionName("All")]
    public IEnumerable<JsonAction> All()
    {
        return from action in this.repository.Get()
               select new JsonAction
               {
                   ID = action.ID,
                   Text = action.Text.Trim(),
                   Description = action.Description.Trim(),
               };
    }

    [HttpGet]
    [ActionName("FindByModule")]
    public IEnumerable<JsonAction> FindByModule(Int64 moduleId)
    {
        return from action in this.repository.FindByModule(moduleId)
               select new JsonAction
               {
                   ID = action.ID,
                   Text = action.Text.Trim(),
                   Description = action.Description.Trim(),
               };
    }
}

Answers


This is because there is a parameter name mismatch. From your route the value 1 is assigned to parameter named id and your action is looking for parameter named moduleId.

First option is to change your route like this:

config.Routes.MapHttpRoute(
    name: "DefaultApi",
    routeTemplate: "api/{controller}/{action}/{moduleId}",
    defaults: new { moduleId = RouteParameter.Optional }
);

Second is to change your URL like this:

http://localhost:37331/api/action/FindByModule?moduleId=1

So the parameter name match.


Need Your Help

rsa with digital signature coding in java

java file rsa

I was running a code for rsa with digital signature on netbeans but got the following error :

Is it ok to use both MATCH AGAINST and LIKE in one MySQL query?

mysql search-engine like match-against

I noticed that MATCH AGAINST cannot search words that have 3 characters or less. So I added LIKE along with MATCH AGAINST in one query.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.