Silverlight + MVC = coolness
Two blogs – one from Tim Heuer and the other from Joe Wardell inspired me to change my website to an MVC site.
My site is basically a Silverlight application. One issue I always had was anytime there was an update to my site, say a new set of photos, users had to go to the site, click on the albums, and then find the album in the list. I wanted this to be more direct in the sense that if could send an SEO-friendly link something like:
http://www.arunmahendrakar.com/albums/maui
and it loads the photos of our Hawaii trip, now that’d be really cool.
Or if I want to share my blog to someone, I can just say:
http://www.arunmahendrakar.com/blog
This is where the above articles came to help, although I used Joe’s article to implement this feature in my site. Basically, I have set up an action method to match these routes. So when you type the ‘blog’ extension in the browser’s address bar, the UrlRoutingModule (the IHttpModule that matches the HTTP request to a route in my ASP.NET application) selects the route:
1: routes.MapRoute
2: (
3: "Blog",
4: "blog/",
5: new { controller = "Home", action = "Blog" }
6: );
The action method itself doesn’t do much other than setting the ViewData dictionary and returning the default view:
1: ViewData["InitParams"] = "Param1=Blog";
All the view pages have a partial view declared in them. The partial view contains the object tag holding a reference to the .xap file. To this, I write the InitParams using a Response.Write statement.
Now to the Silverlight side:
I read the InitParams in the App page and pass it to static members of the Page control. At this point, the Page class decides what control to load on to the main grid. I did not need to do much changes to my Silverlight app, other than few minor tweaks – like making sure that the header image plays only once no matter what page loads, etc, etc, etc.
MVC rocks and Silverlight is simply amazing.
A big thanks to both Tim and Joe for this one.
PS: I use my website as place to put my work – both programming and photography related. My intention is not to market the ‘products’ in my site (actually I’m not selling anything in my site, so I’m in the clear).