Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you need more control of the field being displayed (vs. a built in EditorFor template) create a custom EditorFor template yourself. Inside an EditorFor template, the built in Html Helpers like <code>@Html.TextBox()</code> can be used with <strong>automatic client side validation and Display attributes</strong> which are usually only available to <code>EditorFor</code> and <code>DisplayFor</code>.</p> <p>For example looping through a List of items. The input name has to have an unbroken index.</p> <pre><code>// Optional, if you require a custom input name for binding String fieldName = String.Format("FieldNameForBinding[{0}].Property", index) @Html.EditorFor(m =&gt; m.Property, "MyCustomEditorTemplate", fieldName) </code></pre> <p>Then you can setup your model</p> <pre><code>[CustomValidation(..optional..)] [DisplayFormat(DataFormatString = "{0:F2}", ApplyFormatInEditMode = true)] public decimal? TotalAmount { get; set; } </code></pre> <p>The EditorFor template (in e.g. ~/Views/Shared/EditorFor/MyCustomEditorTemplate.cshtml) Note the name is left empty, it comes from the <code>fieldName</code> automatically. You can see it in the <code>ViewData.TemplateInfo.HtmlFieldPrefix</code>. Now you have complete control over the display of the field.</p> <pre><code>@model object @{ Decimal? actualValue = (Decimal?)Model; } // The TextBox and ValidationMessage "names" are empty, they are filled // from the htmlFieldName given via the @Html.EditorFor() call. @Html.TextBox("", actualValue, new { @class = "cssClass" }) @Html.ValidationMessage("") </code></pre> <p>The idea is that you can customize the input field however you would like, and use e.g. @Html.TextBox() which <strong>outside</strong> of a custom EditorFor template would not utilize the built in client-side validation. You don't need to use the custom naming of the input field, that was simply an example of the usefulness of this solution. You can customize the way the data is presented (CSS, etc.) instead of relying on the built in EditorFor templates.</p>
    singulars
    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. This table or related slice is empty.
    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