MVC Query String Parameters

109 views
Skip to first unread message

scott

unread,
May 6, 2012, 8:12:56 AM5/6/12
to ravendb
I have read several posts on this forum regarding RavenDB and it's
default style of document ID's i.e. "Countries/1" and how they
conflict with embedded query string parameters in a URL.

There have been several solutions offered for this problem and maybe I
missed the following solution or maybe it's frowned upon, but I would
like your opinions.

I was testing various ways to pass the ID of a document and used the
traditional form of a named parameter with Url.Encode() and was able
to pass the ID with very little effort and it was decoded with no
extra work on my part in the controller action.

Is this an acceptable practice or are there some hidden issues that I
am unaware of?

Thanks
Scott

Itamar Syn-Hershko

unread,
May 6, 2012, 8:18:36 AM5/6/12
to rav...@googlegroups.com
What controller action are we talking about? Basically you want to keep most of them, at least the more common, human readable, and encoding doesn't really help

Felipe Leusin

unread,
May 6, 2012, 8:27:36 AM5/6/12
to rav...@googlegroups.com
The ToIntId() extension method is your friend:

public static int ToIntId(this string id)
		{
			return int.Parse(id.Substring(id.LastIndexOf('/') + 1));
		}
 
		public static long ToLongId(this string id)
		{
			return long.Parse(id.Substring(id.LastIndexOf('/') + 1));
		}

This serves me well in a a lot of cases. Just use it when you're passing values to your ViewModel and use the int/long in your ViewModel.

scott

unread,
May 6, 2012, 4:42:45 PM5/6/12
to ravendb
Thanks for the quick replies!

I hadn't thought of having a string ID on the domain model and an int
ID on the viewmodel but that makes perfect sense.

I can just use AutoMapper to map back and forth between the two models
using an IValueResolver class.

I have just started testing different scenarios with RavenDB but it's
been a lot of fun learning a NEW way to work with classes and
persisting data.

A big thanks to the RavenDB crew!

Scott
Reply all
Reply to author
Forward
0 new messages