How to create custom ASP.NET MVC controls in class libraries

I am trying to create some .ascx controls in the class library for plugins for the CMS I am creating.

My project type is a typical C # class library with links added for system.web.mvc and friends.

My problem occurs when trying to create a strongly typed user control. My control is as follows:

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

Even if I have another public class in the same project in the namespace TagCloudWidget.Models, I cannot get the file .ascxto recognize this. I tried turning it on Importsfor the namespace, but then it just complains that the namespace does not 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;
    }
}
}

, ?

. , , , . System.Web System.Web.Mvc. codebehind, "using System.", System.Web System.Web.Mvc . , . . , , , , . ?

+3
2

, -. , , , . , . , 1.0, , , .

0

! , .ascx "" , "". , / . codebehind!

() , , , app/bin, my/widgets, " ...", , ASP.NET MVC, , , .

0

Source: https://habr.com/ru/post/1711376/


All Articles