ASP.NET MVC Routes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • shapper

    ASP.NET MVC Routes

    Hi,

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

    var dataTokens = new RouteValueDicti onary();
    dataTokens.Add( "namespaces ", new HashSet<string> (
    new string[] {
    "MyApp.Blog.Con trollers",
    "MyApp.Forum.Co ntrollers",
    "MyApp.Controll ers"
    }));

    routes.Add(
    new Route("ns/{controller}/{action}/{id}", new MvcRouteHandler ()) {
    Defaults = new RouteValueDicti onary(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
  • Cowboy \(Gregory A. Beamer\)

    #2
    Re: ASP.NET MVC Routes

    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:

    UPDATES: > Added some detail about routing with IIS7.  See end of post :) > .NET 3.5 SP1 includes ASP.NET Routing as part of the framework.  If you’re using ASP.NET AJAX (or a…


    And there is a route tester Haack wrote
    UPDATE: I’ve added a NuGet package named “routedebugger” to the NuGet feed, which will make it much easier to install.


    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.

    --
    Gregory A. Beamer
    MVP, MCP: +I, SE, SD, DBA

    Subscribe to my blog


    or just read it:


    *************** *************** **************
    | Think outside the box! |
    *************** *************** **************
    "shapper" <mdmoura@gmail. comwrote in message
    news:d6080ed4-7abc-40a1-a6bb-042da45c1043@i7 6g2000hsf.googl egroups.com...
    Hi,
    >
    I was checking the new ASP.NET MVC Preview 4 features and I found the
    following:
    >
    var dataTokens = new RouteValueDicti onary();
    dataTokens.Add( "namespaces ", new HashSet<string> (
    new string[] {
    "MyApp.Blog.Con trollers",
    "MyApp.Forum.Co ntrollers",
    "MyApp.Controll ers"
    }));
    >
    routes.Add(
    new Route("ns/{controller}/{action}/{id}", new MvcRouteHandler ()) {
    Defaults = new RouteValueDicti onary(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

    Comment

    Working...