views:

368

answers:

2

I'm trying to build some .ascx controls into a class library for plugins for a CMS I'm building.

My project type is a typical C# class libary with references added for system.web.mvc & friends.

My problem arises in trying to create a strongly-typed user control. My control looks like this:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<TagCloudWidget.Models.TagCloudWidgetData>" %>

Even though I have another public class in the same project under the namespace TagCloudWidget.Models, I can't seem to get the .ascx file to recognize this. I've tried including Imports for the namespace, but then it just complains that the namespace doesn't exist. The TagCloudData class file looks like this:

namespace TagCloudWidget.Models
{
public class TagCloudWidgetData
{
    public IList<TagCount> TagCounts { get; set; }
    public ContentTypes ContentType;
    public string Controller;
    public string Action;

    public TagCloudWidgetData(IList<TagCount> tagCounts, ContentTypes contentType, string controller, string action)
    {
        TagCounts = tagCounts;
        ContentType = contentType;
        Controller = controller;
        Action = action;
    }
}
}

Can you see what I'm doing wrong?

Since the suggestion below, I've tried adding a code-behind file. I think I'm closer to figuring out what's wrong, but I'm still not able to find a solution. In the project, I've added references to System.Web and System.Web.Mvc. But, in the using section of the codebehind file, when I type "using System.", auto-complete doesn't even show System.Web or System.Web.Mvc as available options. It's like they just don't exist on disc. Other projects are able to include them and reference them just fine. I suppose this is the source of my problem, so I'm hopeful once I figure this out the rest will just fall into place. Ideas?

A: 

I've had similar problems with an application that I started with the beta release. The only thing I've found that works is to create a code-behind file for the control and define the inheritance in the code-behind. Then in the control, have it inherit from the class defined in your code-behind. In newer projects, built from scratch using 1.0, I don't have this problem -- but then again I don't have my partial classes defined in a library, either.

tvanfosson
Thanks, I'll try that. This is a new project built from scratch with 1.0, so maybe we're still missing some small piece of the puzzle.
Joe Future
Hmm... nope, that hasn't solved my problem yet.
Joe Future
A: 

Success! Somehow, my .ascx file had been marked "content" in the file properties instead of "compile". Once I fixed that, I can now reference the necessary assemblies and load/run the plugin without problems. Thanks for the tip on the codebehind file!

(update) The other tip I figured out last night is that my plugin also has to be in the app's /bin directory as well as my /widgets directory, otherwise I get a "Could not load type..." exception. I haven't figured out yet how to wire up ASP.NET MVC so I only have to have it in 1 place, but when I do, I'll post back here.

Joe Future