How to work RavenDB Id with ASP.NET MVC Routes

Posted by shiju on ASP.net Weblogs See other posts from ASP.net Weblogs or by shiju
Published on Fri, 04 Jun 2010 05:59:00 GMT Indexed on 2010/06/04 6:10 UTC
Read the original article Hit count: 714

Filed under:
|
|
|

By default RavenDB's Id would be sperated by "/". Let's say that we have a category object, the Ids would be like "categories/1". This will make problems when working with ASP.NET MVC's route rule. For a route category/edit/id, the uri would be category/edit/categories/1. You can solve this problem in two ways

Solution 1 - Change Id Separator

We can use different Id Separator for RavenDB Ids in order to working with ASP.NET MVC route rules. The following code specify that Ids would be seperated by "-" rather than the default "/"

 documentStore = new DocumentStore { Url = "http://localhost:8080/" };

 documentStore.Initialize();

 documentStore.Conventions.IdentityPartsSeparator = "-";


The above IdentityPartsSeparator would be generate Ids like "categories-1"

Solution 2 - Modify ASP.NET MVC Route

Modify the ASP.NET MVC routes in the Global.asax.cs file, as shown in the following code

 

routes.MapRoute(

    "WithParam",                                           // Route name

    "{controller}/{action}/{*id}"                         // URL with parameters

    );

 We just put "*" in front of the id variable that will be working with the default Id separator of RavenDB

© ASP.net Weblogs or respective owner

Related posts about ASP.NET

Related posts about ASP.NET MVC