-1

i have a PropertyController, which I use to serve a bunch of pages. For example..

/Property
/Property/{id}
/Property/add
/property/edit/{id}

I now need to do a bunch of stuff based on a particular property I will need to do serve pages like this:

/Property/{id}/images/add
/Property/{id}/images/edit/{id}
/Property/{id}/rooms/add
/Property/{id}/rooms/edit/{id}

I think I need to build a new ImagesController and RoomsController, but do I need to but these in a folder structure? My RouteConfig is currently set to the default MapRoute rule ({controller}/{action}/{id}

halfer
  • 19,824
  • 17
  • 99
  • 186
Gavin5511
  • 791
  • 5
  • 31

1 Answers1

1

You don't need to reflect your routing structure in your folders structure.

Check this one out: ASP.Net MVC support for Nested Resources?.

Effectively your routing string is a regExpression to match whatever comes in from a requester. And if there's a match it's trying to bind all the variables in your expression to values from the HTTP request.

In regard to creating new controllers - a rule of thumb is to create a controller per resource / business entity. So in your case I would say yes to ImagesController, RoomsController and PropertyController.

Community
  • 1
  • 1
amdmax
  • 771
  • 3
  • 14
  • Thanks, that seems to make sense. Although just testing it out, i seems the routes are still available via the old format as well as the new one. /images and /property/1234/images. Is that how it should be? – Gavin5511 Dec 04 '16 at 20:53
  • The /images works out because you have the default /controller/action defined. While being parsed from the query string we can inherit the controller name to be ImagesController. If you don't want it to be available you will have to change your default route – amdmax Dec 04 '16 at 22:03