Silverlight and QueryString Parameters via LINQ
I’ve been privaliged enough to be working with Silverlight recently, and I’m really pleased with everything about it so far. Really, the most aggravating thing is that the Linux version (Moonlight) is a version behind.
Cutting to the chase here, I was trying to find an elegant solution to getting a bunch of data from a QueryString into my Silverlight application, sadly for my situation there was not a more robust data transfer mechanism available, so the QueryString had to suffice.
Getting to the QueryString from Silverlight isn’t as painless as it is from ASP.NET. Nothing simply like Request.QueryString[“mode”] works in Silverlight, so to get arround that I came up with this sexy little LINQ query to make it as close to that one badass ASP.NET line.
String mode = (from v in System.Windows.Browser.HtmlPage.Document.QueryString where v.Key == "mode" select v.Value).SingleOrDefault();
Is there a better way to get at the QueryString from Silverlight? Not that I’ve found, let me know if you have a better approach.