ASP.NET MVC 3/4 Razor - public action method not found - how to debug

37 views Asked by At

I'm just working on an existing C# ASP.NET MVC 3/4 application and I am getting an error when trying to call a method.

The call is

@url.Action("Bob", "BobController")

The controller is:

[Authorized]
class BobController ... 
{
    public ActionResult Bob() 
    {
        // ...
    }
}

The error I get is

A public action method 'Bob' was not found on controller MyController

What is happening, the constructor is being fired in the class so I can see the call being made and arriving at the controller, then it jumps to the Application_Error in global.asax.

Just wondering, if there is a way of determining what it is looking for (missing permission, incorrect route etc.) so I can see why it is failing?

Regards

2

There are 2 answers

0
IceCode On BEST ANSWER

You dont need to postfix the controller in the @Url.Action part with ´controller´ as the framework already takes care of that for you.

It should be enough like the following: @Url.Action("Bob", "Bob")

0
AndyW On

The issue was due to a custom attribute that was attached to the method being called in the controller throwing an exception in its implementation - this was causing the jump to the global.asax error handler.

I found it by chance, hence my question on a good way to try and identify these types of issue.