No Free Time

July 3, 2008

ASP.Net MVC: Giving MasterPages access to ViewData

Filed under: .net, mvc — Tags: , — andrewmyhre @ 6:38 pm

If you want to include ViewData in the MasterPage UI, you can.

ASP.Net MVC MasterPages are System.Web.Mvc.ViewMasterPage - this is a generic type just like System.Web.Mvc.ViewPage. So you can type it with a ViewData object, like this:

public partial class MyTemplate : ViewMasterPage<SomeViewData>

As soon as you do this you’re saying that the SomeViewData class is the only ViewData object that can be used on any page using this template. Not a problem though, just create a base ViewData class.

public class SiteWideViewData
{
}

public class PageViewData : SiteWideViewData
{
}

This of course means no more default ViewData objects and no more return View(); I found the easiest way to deal with that is to create a static property on the base ViewData:

public class SiteWideViewData
{
public static SiteWideViewData Default { get { return new SiteWideViewData(); } }
}

Now I can do this:

public ActionResult MySimpleControllerMethod()
{
return View(SiteWideViewData.Default);
}

And that seems to work okay.

June 29, 2008

ASP.Net MVC Toolkit Download

Filed under: .net, mvc — Tags: , — andrewmyhre @ 8:27 pm

Took me ages to find a link to download this sucker, so here’s the download link.

Download MVC Toolkit for MVC Preview 1

Note: As Simone noted in the comments, this toolkit is built against MVC Preview 1 and hence doesn’t work with Preview 2 or 3.

UPDATE:

I thought I needed it because there are so many MVC how-to articles referencing Preview 1, but it turns out much of the functionality is now rolled up into Preview 3. This assembly is now redundant, which is why it’s so hard to find. It’s *supposed* to be.

January 9, 2008

MVC Not Ready For TFS?

Filed under: .net, mvc, tfs — Tags: , , — andrewmyhre @ 4:55 am

High expectations this year. I want to have at least a couple of commercial MVC website under my belt by 2009, and I want to be using Team Foundation 2008. Part of this will be to make use of Web Deployment Projects combined with Team Builds. What would be great is if I could have the team server spitting out nicely labelled development, staging and production builds of our sites, and if I could configure the config file changes using web deployment projects. Also I would like it to produce metrics around unit tests, integration test and interface tests, and anything else that would be useful (code metrics? haven’t explored this fully yet). I want our projects managers/testers to be able to know what build they’re looking at and easily get a summary of the changesets involved in that build.

So that’s the plan. We are currently running TFS 2005, but the documentation says that VSTS 2008 and TFS 2005 are compatible, so what I’m going to do first is set up a ‘Sandbox’ MVC project in it’s own Team Project space, for us to play with and try things out.

So started by creating a new Team Project, then a new ASP.Net MVC Web Application and Test project (makes sense - want to try out the built in unit testing functionality).

Then I choose the project in TFS I want to use as the repository.

At this stage everything is created and ready to check in, so I perform a solution check-in. All looks good, I can see padlocks next to all my files. But if I close and re-open the solution, I get the message:

The project ‘MvcApplicationTest’ is under source control. This version of Visual Studio .NET does not support source controlled projects. Any changes that you make to this project will not be propagated to source control.

Strange! And now the test project is no longer source-controlled. If I create a build to run these tests on the build server it won’t have any of the project files to compile and run.

To clarify, I’m using Visual Studio Team System 2008 RTM. Anyway, I’ve tried a couple of things, like deleting the test project and adding a new test project. Trouble is I can’t write tests against the MVC controllers due to some weird issue - I can’t add a reference to the version of System.Web.Extensions.dll referenced by the MVC project (3.6.0.0) to the test project. It’s in the GAC, but doesn’t appear in the components list (I see 3.5.0.0, the version that ships with VS 2008). So I can’t even create my own test projects.

Bit of a worry and I hope it gets addressed when MVC goes into full release…

Older Posts »

Blog at WordPress.com.