Friday, April 17, 2009

DynamicData cleanup

Last time I've described a way of merging the DynamicData capability with an ASP.NET MVC application. This time I'll show you how to make the DynamicData part be stored in the right place.

First of all it's kind of awkward to have the Site.css, Site.master and the rest in the root folder. Let's face it: this sucks! It'd be nice if we could have those DynamicData-related stuff inside the DynamicData folder where they could live happily ever after.

It's not impossible but there are two small glitches that you need to be aware of. But first things first.

Step 1. Grab the Site.css, Site.master in solution explorer and drag them to the DynamicData folder.

Step 2. Open the DynamicData\Site.master file and change the

<img alt="Back to home page" runat="server" src="DynamicData/Content/Images/back.gif" />

with

<img alt="Back to home page" runat="server" src="~/DynamicData/Content/Images/back.gif" />

Node the Tilda addition in the image src attribute!

Step 3: Change the master page for pages. In the folder DynamicData\PageTemplates you'll find templates for all the generated pages. Open them one by one (there are 5 of them: Details.aspx, Edit.aspx, Insert.aspx, List.aspx and ListDetails.aspx) and change the MasterPageFile attribute from

MasterPageFile="~/Site.master"

to

MasterPageFile="~/DynamicData/Site.master"

That's it! There's nothing more to it. From now on your application structure is cleaner and there's noting polluting the clear ways of the ASP.NET MVC project!


Have fun!

No comments: