Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC: Namespaces in routes

I have a small problem, I can't find any documentation on the namespaces parameter for MapRoute. Can anyone explain how I should use that?

I want to map ~/Controllers/Projects/ProjectController.cs to this url ~/Projects/ but I also have other controllers in ~/Controllers/Projects that I want to map to other URL's. So I need to add a namespace for those URL's. How to?

like image 259
Kim Johansson Avatar asked Apr 09 '09 13:04

Kim Johansson


People also ask

Can we have multiple routes in MVC?

Multiple Routes You need to provide at least two parameters in MapRoute, route name, and URL pattern. The Defaults parameter is optional. You can register multiple custom routes with different names.

What is namespace routing?

In its simplest form, a Namespace Routing Language (NRL) schema consists of a mapping from namespace URIs to schema URIs. An NRL schema is written in XML. DSDL Part 4 (ISO/IEC 19757-4), NVDL is based on NRL.

Which namespace is used for ASP.NET MVC?

The System. Web. Mvc namespace contains classes and interfaces that support the ASP.NET Model View Controller (MVC) framework for creating Web applications. This namespace includes classes that represent controllers, controller factories, action results, views, partial view, model binders, and much more.


2 Answers

The namespaces parameter lets you specify where the infrastructure should search for additional controller types, by default mvc will search ALL classes in the executing assembly (the site project), and those that implement IController become candidates.. basically, you can put the controllers in as many nested folders as you want if they are part of the asp.net mvc project..

The main use of the namespaces parameter is if you want to store your controller classes in an external assembly, in which case you can specify the namespace to where those controllers are.

like image 90
meandmycode Avatar answered Oct 16 '22 04:10

meandmycode


I am not sure if it is what you want.

http://haacked.com/archive/2008/11/04/areas-in-aspnetmvc.aspx

like image 1
Canton Avatar answered Oct 16 '22 05:10

Canton