What is the location of the default editor and display templates in Asp.net MVC3?

Where are the default Razor editor templates and display templates (e.g. String.cshtml, DateTime.cshtml) located when installing Asp.Net MVC 3?

+6
source share
2 answers

There are no default templates. The Razor Editor and Display methods are extension methods of the HtmlHelper class. You can use them, or you can develop your own extension methods, like this example.

 public static MvcHtmlString MyTextBoxFor<TModel, TProperty>(this HtmlHelper<TModel> helper, Expression<Func<TModel, TProperty>> expression) { MvcHtmlString result = InputExtensions.TextBoxFor(helper, expression); // do modification to result return result; } 
+1
source

If you have DotPeek or Reflector you can find the type DefaultDisplayTemplates , there you will find templates. But keep in mind that they are in code format, not WebForm or razor format, so it’s a little harder to interpret.

StringTemplate

 internal static string StringTemplate(HtmlHelper html) { return html.Encode(html.ViewContext.ViewData.TemplateInfo.FormattedModelValue); } 

(There was no default DateTime template that I could find)

DecimalTemplate

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

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


All Articles