Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This seem to be by design. You will have to make string template more general. String template works as default template for every non-complex model that doesn't have it's own template.</p> <p>Default template for string (FormattedModelValue is object):</p> <pre><code>internal static string StringTemplate(HtmlHelper html) { return html.Encode(html.ViewContext.ViewData.TemplateInfo.FormattedModelValue); } </code></pre> <p>Template selection looks like this:</p> <pre><code>foreach (string templateHint in templateHints.Where(s =&gt; !String.IsNullOrEmpty(s))) { yield return templateHint; } // We don't want to search for Nullable&lt;T&gt;, we want to search for T (which should handle both T and Nullable&lt;T&gt;) Type fieldType = Nullable.GetUnderlyingType(metadata.RealModelType) ?? metadata.RealModelType; // TODO: Make better string names for generic types yield return fieldType.Name; if (!metadata.IsComplexType) { yield return "String"; } else if (fieldType.IsInterface) { if (typeof(IEnumerable).IsAssignableFrom(fieldType)) { yield return "Collection"; } yield return "Object"; } else { bool isEnumerable = typeof(IEnumerable).IsAssignableFrom(fieldType); while (true) { fieldType = fieldType.BaseType; if (fieldType == null) break; if (isEnumerable &amp;&amp; fieldType == typeof(Object)) { yield return "Collection"; } yield return fieldType.Name; } } </code></pre> <p>So if you want to create template only for string, you should do it like this (String.ascx):</p> <pre><code>&lt;%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl&lt;object&gt;" %&gt; &lt;% var model = Model as string; %&gt; &lt;% if (model != null) { %&gt; &lt;%: model %&gt; (&lt;%: model.Length %&gt;) &lt;% } else { %&gt; &lt;%: Model %&gt; &lt;% } %&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload