in

Chennai .Net User Group

A platform that enables you to Learn, Share & Grow (India's first .Net user group)

Shiju Varghese's Blog

How to work RavenDB Id with ASP.NET MVC Routes

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

Read the complete post at http://feedproxy.google.com/~r/ShijuVBlog/~3/KrjIZoJAKEo/how-to-work-ravendb-id-with-asp-net-mvc-routes.aspx

Only published comments... Jun 04 2010, 08:59 AM by Shiju Varghese's Blog
Copyright © 2002-2008 Chennai .Net User Group. All Rights Reserved. Microsoft and Microsoft logo's are trademarks of Microsoft Corporation