vote up 4 vote down star
1

I'm having a tricky issue (bear with me as I'm new to MVC) with trying to use a controller (and a route subsequently) with the name PropertiesController.

I believe this is because there is a directory (which I can't really remove) called "Properties" in my solution. Is there a way round this?

The route setup is just one simple route:

routes.MapRoute(
    "Default", // Route name
    "{controller}/{action}/{id}", // URL with parameters
    new { controller = "Properties", action = "List", id = "" } // Parameter defaults 
);

and the error I get in IIS7 when requesting "http://localhost/aptment2/properties/" is:

alt text

Surely there is a way round this that I just can't find? Cheers.

flag

73% accept rate
Are you trying to browse to that view directly or are you going through the default.aspx page first (such as with an F5 or Ctrl+F5)? Just curious if the route registration is getting bypassed which happens f you have that view set as the start page instead of default.aspx. – mannish Jul 1 at 19:00

3 Answers

vote up 1 vote down check

Since someone else is having the same problem, I'm guessing that you're running into a reserved keyword here (I imagine ClassControllers are out as well).

It's not the first time it's happened either - digging deeper into the internals of the environment, you can't route to Windows' reserved keywords either.

link|flag
vote up 1 vote down

Running a quick test, I get the same behavior. Is it a viable option to use something other than Properties?

link|flag
I'd prefer not to if at all possible, after all the idea of MVC is that you have complete control and your URL naming scheme is to be as clean as possible! – Kieran Benton Jul 1 at 19:24
Well, sort of. That's the idea behind routing, not necessarily just MVC, but regardless, MVC reles on certain conventions and that includes not using reserved words or names of other resources. I would suggest either looking into locking down that route definition further (I'll add an edit with a suggestion) or coming up with a different name for your controller. – mannish Jul 1 at 20:37
I tried locking down the route a bit further and get the same result. You might be SOL on this but I'll be curious to see if there's a way around it. – mannish Jul 1 at 20:41
Looks like you're right - oh well, will have to get my thesaurus out! – Kieran Benton Jul 1 at 22:03
FWIW, we have a controller called PropertyController that works just fine in one of our projects. But we have a convention of using singular names for controllers (as opposed to plural such as 'Properties'). – mannish Jul 1 at 22:43
vote up 0 vote down

I don't know if it's an option for you, but you could try to disable routing to existing files.

routes.RouteExistingFiles = false;
link|flag

Your Answer

Get an OpenID
or

Not the answer you're looking for? Browse other questions tagged or ask your own question.