ASP.NET MVC Routes

S

shapper

Hi,

I was checking the new ASP.NET MVC Preview 4 features and I found the
following:

var dataTokens = new RouteValueDictionary();
dataTokens.Add("namespaces", new HashSet<string>(
new string[] {
"MyApp.Blog.Controllers",
"MyApp.Forum.Controllers",
"MyApp.Controllers"
}));

routes.Add(
new Route("ns/{controller}/{action}/{id}", new MvcRouteHandler()) {
Defaults = new RouteValueDictionary(new {
action = "Index",
id = (string)null
}),
DataTokens = dataTokens
});

Does this it mean that I can differentiate two distinct parts of my
application such as the web site itself and the CMS.

For example I could have:

Site/Home/Contacts

and

CMS/Documents/List

And can I have the view in two different folders?

For example:

-Views
-----Site
---------Contacts
---------Document
--------------List
-----CMS
---------Document
--------------List
--------------New
-----Shared

As you can see Document List View is different in the web site and in
the CMS.
Can I organize my views in such a way?

Thanks,
Miguel
 
C

Cowboy \(Gregory A. Beamer\)

I am not sure I am understanding what you are attempting, so I will go
through routes and try to see if I can cover your requirements.

Routing does give you the ability to organize your views and controllers how
you would like. If you cannot do it by routing alone, there are ways you can
alter the code to get precisely what you desire. There is quite a bit that
you can override in the framework.

Yes, you can set up different sections differently. And routing is certainly
one way. But altering the way views are stored is not entirely necessary to
have the URL string vary. The physical organization (where the aspx files
are stored, if you are using aspx for your views) need not match the logical
organization (route).

I suggest you examine how different people have organized their sites. Rob
Connery's sample application (http://www.codeplex.com/mvcsamples) has a lot
in it that can help you get a grasp of how some of these features can work
in your application. There is also Kigg (http://www.codeplex.com/Kigg/), a
Digg clone in MVC.

Another way to learn is the videos on asp.net:
http://www.asp.net/learn/3.5-SP1/default.aspx has the storefront at the
bottom (mvcsamples).
there are also a variety of vids by Hanselman at http://www.asp.net/mvc/

Now that routing is in .NET 3.5 SP1, and decoupled from MVC, you can find
all sorts of blog entries on it:
http://blogs.msdn.com/mikeormond/archive/2008/06/21/asp-net-routing-and-authorization.aspx
http://chriscavanagh.wordpress.com/2008/03/11/aspnet-routing-goodbye-url-rewriting/

And there is a route tester Haack wrote
http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx

If you write your routing correctly, you can even mix legacy applications
with MVC, which means you do not have to rewrite everything at once.


shapper said:
Hi,

I was checking the new ASP.NET MVC Preview 4 features and I found the
following:

var dataTokens = new RouteValueDictionary();
dataTokens.Add("namespaces", new HashSet<string>(
new string[] {
"MyApp.Blog.Controllers",
"MyApp.Forum.Controllers",
"MyApp.Controllers"
}));

routes.Add(
new Route("ns/{controller}/{action}/{id}", new MvcRouteHandler()) {
Defaults = new RouteValueDictionary(new {
action = "Index",
id = (string)null
}),
DataTokens = dataTokens
});

Does this it mean that I can differentiate two distinct parts of my
application such as the web site itself and the CMS.

For example I could have:

Site/Home/Contacts

and

CMS/Documents/List

And can I have the view in two different folders?

For example:

-Views
-----Site
---------Contacts
---------Document
--------------List
-----CMS
---------Document
--------------List
--------------New
-----Shared

As you can see Document List View is different in the web site and in
the CMS.
Can I organize my views in such a way?

Thanks,
Miguel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top