NibblyPig
NibblyPig

Reputation: 52922

Simple MVC route does not work

I've created a new MVC project. I've created an empty controller called APIController:

public class APIController : Controller
{
    public ActionResult Index()
    {
        return View();
    }

    public ActionResult Test()
    {
        return View();
    }
}

I've created the corresponding views, which are empty apart from the word 'index' and 'test'.

When I go to myurl.com/Account it works

When I go to myurl.com/Account/Test I get an xml error saying:

No HTTP resource was found that matches the request URI [...]

No type was found that matches the controller named 'Account'.

This must be a noob error. Everything else in the project is default. The RegisterRoutes method is the default:

routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

What silly thing am I missing?

Bonus points if you can explain why the error is an XML error and not the standard yellow screen of death...

Upvotes: 0

Views: 91

Answers (2)

NibblyPig
NibblyPig

Reputation: 52922

Problem solved.

Turns out if you call your controller APIController MVC treats it completely differently. Renaming it to ABCController worked great.

I'm not writing an API, I'm writing a website that manages an API!

Argh, thanks MVC!

Upvotes: 2

Andy T
Andy T

Reputation: 9881

Can you check if the controller you created is inheriting ApiController instead of the standard Controller?

This would also explain why the error message is being returned in XML.

Upvotes: 0

Related Questions