EditorTemplates in the class library

In the ASP.NET-MVC2 project, I created some user controls that are in the Views \ Shared \ EditorTemplates and DisplayTemplates folders.

I am trying to pull these templates into a class library to make them reusable, how to do it!

I don't know if this can help, but a little more detail; some of them are called such types (string, Int32, etc.), and some are called RemoteCombo and are set using the template hint in UIHint.

+3
source share
1 answer

Unfortunately, you cannot just create a library and put ascx files there. You will need to create a code-only version of your templates that displays the corresponding html.

Microsoft , System.Web.Mvc.dll

- MVC, ( " " )

( System.Web.Mvc.dll)

internal static string DecimalTemplate(HtmlHelper html)
{
    if (html.ViewContext.ViewData.TemplateInfo.FormattedModelValue == html.ViewContext.ViewData.ModelMetadata.Model)
    {
        html.ViewContext.ViewData.TemplateInfo.FormattedModelValue = string.Format(CultureInfo.CurrentCulture, "{0:0.00}", new object[] { html.ViewContext.ViewData.ModelMetadata.Model });
    }
    return StringTemplate(html);
}

Reflector System.Web.Mvc.Html.

+1

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


All Articles