Damien Thouvenin

ASP.NET MVC error after migrating project from beta to RTM "could not load type System.Web.Mvc.ViewUserControl<...>" - Solved

I've been working on and off on an ASP.NET MVC project for a year or so. I migrated it with each new release, sometimes with a lot of ease, sometimes rather painfully.

When upgarding from beta 5.0 to ASP.NEt MVC 1.0 (RTM) everithing seemed fine at first. Then I started refactoring some of my views which had code-behind files but no code. It was ok for most views but the strongly typed partial views didn't work: I got a "parler error message: could not load type System.Web.Mvc.ViewUserControl<xxx>" (where xxx is my model class).

I then created an entriely new project and moved some of my code in it, just to check: and it worked !

It took me some time to realize what was wrong : the web.config file in the views directory has changed. When copying the file from the newly created project to the old project, everything is fine again !

Posted: Jun 27 2009, 02:49 PM by d.th | with no comments
Filed under:
ASP.NET MVC Controller extensions

In the course of preparing a soon-to-come showcase on ASP.NET MVC I needed to redirect a controller method to another controller's. I found this post by Matt hawley that got me started but I had to fix a bug. Since I had already created my own extension methods to allow sending a file as attachment, I took the liberty of repackaging Matt's code and mine into a single class.

Zipped source code is here : MvcControllerExtensions.zip

So what's in it ? 

A. Changes from Matt's code :

I changed all RedirectToAction<T>(this T controller, ... to RedirectToAction<T>(this Controller controller, ...  so that the target controller (T) does not have to be the invoking controller (this).

I also moved the class to System.Web.Mvc so that it doesn't require additional usings. It's enough that you include the code in your project.

B. My extension methods :

I first created a DelegatedActionResult which allows Controller methods to delegate execution of the action, like so :

return new DelegatedActionResult(c => c.HtppContext.response.Close());

Then I used this to extend the Controller class with a new method SendFileAsAttachment, which comes in two flavours : you can either provide a filename or a delegate that get called to write into the http response stream.

    public ActionResult GetLogo(string companyName)
    {
        return this.SendFileAsAttachment(Server.MapPath("~/App_Data/Logos/" + companyName + ".jpg"));
    }

or

    public ActionResult GetFile(int fileId)
    {
        var database = DataProvider.GetFileManager();
        return this.SendFileAsAttachment(database.GetFilename(fileId),
                                        (fileId, outputStream) =>
                                         database.LoadFile(fileId, outputStream));
    }

 

Posted: May 25 2008, 10:50 AM by d.th | with no comments
Filed under: , , ,
Opening

Cool ! I've answered Joe Stagner's invitation to come an blog about ASP.NET and, a few hours later : tada ! I now have a community blog !

Since I also have a blog in french, I'll start by translating a few posts ; in the meanwhile, if there are subjects you'd like to see me digg, please write to me. My realms are classic ASP.NET, Server Controls, Ajax, ASP.NET MVC, SubSonic and SQL Server 2005, plus some musings on Agile methods (especially Scrum).

 

More Posts