Navigation Url Parameter (Query String) syntax

Jun 11, 2010 at 8:27 AM


I'm having trouble passing parameters to a page using a navigation container via a url. I've got a StatefulBrowsingContainer with the browser integration behavior enabled. Entering a url of the form http://<server_Name>/path?Parameter1=value1&Parameter2=value2 results in an error from the navigation handler saying something about '?' characters not being allowed in urls. Is this the default behavior? If so how do I pass arbitrary parameters to the page with out using url mapping?

Jun 11, 2010 at 8:55 AM
Edited Jun 11, 2010 at 11:41 AM

Well, as you know internally, within a SL application, nRoute uses relative urls which as the error points out does not allow certain characters such as "?" - this is on par with ASP.NET MVC. Now, as I understand you want to pass in parameters to the application, well the correct way, which also plugs into the nRoute infrastructure, is to use Url tokens. So say we have an navigation content declaration like:


then you can ask for this resource using a url like:


Note, the Url is passed in the anchor part of Url (ie. the Fragment property of Uri) - so with the above the CustomerId will be "AKFID" and SalesId will be 21. And the benefit of using this approach is that it can be accessed in your VM by applying ISupportNavigationLifecycle or more easily by inheriting from the NavigationViewModelBase class. However, when you don't want to use nRoute's infrastructure or you just want to extract the Url parameters directly then you'll need to talk to Silverlight's HtmlDocument class and use its QueryString property, which is an IDictionary<string, string> type.


Jun 11, 2010 at 12:29 PM

Thanks for the prompt reply.

I am using a view model with ISupportNavigationLifeCycle as well and while in most instances I'd be using the url token format ala ASP.NET MVC, for this one page I won't know all the parameters upfront which is why I'd like the query string to be parsed and the ParameterCollection be populated from the parsed query string. Is there no way of doing that?

Jun 11, 2010 at 2:45 PM

Like I said if you want to get hold of a normal url-parameters (like with your url http://<server_Name>/path?Parameter1=value1&Parameter2=value2) then use HtmlDocument's Querystring property because nRoute only uses the fragment part of the Url. Also, the potential use of name-value parameters within Url-fragments is somewhat murky:

It is not clear whether you should apply the URL encoding rules discussed below to fragment identifiers. The specifications seem to say "yes", whereas browsers often fail to work if you URL encode fragment identifiers. It is best to avoid "unsafe" characters in those identifiers, i.e. basically in your anchor names -

With regards to relative urls within nRoute, you can't have name-value style parameters and quite obviously it doesn't parse them either. It might be possible to change this behavior but no gurantees.


Jun 16, 2010 at 10:41 AM

Thanks Rishi.

It seems MapNavigationContentAttribute as AllowMultiple = true and thus you're able to map the same page to multiple routes with potentially different parameters. This seems to have solved my problem nicely as instead of having to deal with query strings, I just mapped the page to as many routes as I needed to support, each with their own parameters.

Jun 17, 2010 at 12:50 PM

Cool solution - but just as another idea, it is possible to gather the Querystring parameters and push them as a NavigationRequest. As you know a navigation request can take in (via it's Request Parameter's property) an arbitrary number of name-value pairs as input which you could then check and use. Just a thought.