Monday, February 27, 2012

MVC and Facebook for real

Believe it or not. I am about to release my first professional MVC 3 application for a client. I have done a few personal projects to learn and play with. But this one is for real and will get high traffic. This site also has a facebook integration on creating and managing events.

Since this isn't my first MVC 3 application, I really wanted to get a better grasp on partial views and how to implement them successfully. What I knew about partial views before going into this project is they are the ideal substitute of custom controls in a webform app. My first ever MVC 3 project coming from webforms I was expecting it to be a self contained "drop in" piece of functionality. And the first code example I saw was calling HTML.RenderPartial("_partial.cshtml"). Well I didn't really get how it was self contained, the partial views depended on objects in the viewbag without going back to the server. In order to different object it felt as if I had to much .net code going on in the partial view for it even to be considered a 'view'.

Even though I have heard and seen Controller Actions return a partial view I couldn't figure out why a controller action would just return a partial when I want a full user experience. Looking back this is mainly new syntax learning with razor vs traditional asp code. I finally ran into HTML.RenderAction() What a game changer it was. I could now drop in functionality independent of location and it would render proper html.