Note that there are some explanatory texts on larger screens.

plurals
  1. POUnobtrusive javascript adding data to @Html.HiddenFor
    primarykey
    data
    text
    <p>I have a hidden field on a form that is created in Razor using the <code>@Html.HiddenFor</code> helper:</p> <pre><code>@Html.HiddenFor(model =&gt; model.BidID, new { id="bidItemID" }) </code></pre> <p>My View model looks like this:</p> <pre><code>public class BidEditVM { [Display(Name = "Bid ID")] public int BidID { get; set; } [StringLength(51)] [Display(Name = "Customer Name")] public string CustomerName { get; set; } [StringLength(75)] [Display(Name = "Bid Name")] public string BidName { get; set; } [Display(Name = "Amount")] public decimal Amount { get; set; } [Display(Name = "Time")] public DateTime BidTime { get; set; } } </code></pre> <p>When the HTML is rendered, unobtrusive javascript adds it's stuff to the hidden input field even though it will never require validation:</p> <pre><code>&lt;input id="bidItemID" type="hidden" value="5198" name="BidID" data-val-required="The Bid ID field is required." data-val-number="The field Bid ID must be a number." data-val="true"&gt; </code></pre> <p>What's odder is that the message and validation it adds aren't even part of the view model for this partial view. The view looks like this:</p> <pre><code>@model AuctionAdmin.Models.ViewModels.BidEditVM @using (Ajax.BeginForm("UpdateBid", new AjaxOptions { HttpMethod = "Post", UpdateTargetId = "modalBidInfo" })) { @Html.ValidationSummary(true) @Html.HiddenFor(model =&gt; model.BidID, new { id="bidItemID" }) &lt;fieldset&gt; &lt;legend&gt;Edit Bid&lt;/legend&gt; &lt;div class="display-label"&gt;@Html.LabelFor(model =&gt; model.CustomerName)&lt;/div&gt; &lt;div class="display-field"&gt; @Html.DisplayFor(model =&gt; model.CustomerName) &lt;/div&gt; &lt;div class="display-label"&gt;@Html.LabelFor(model =&gt; model.BidName)&lt;/div&gt; &lt;div class="display-field"&gt; @Html.DisplayFor(model =&gt; model.BidName) &lt;/div&gt; &lt;div class="editor-label"&gt;@Html.LabelFor(model =&gt; model.Amount)&lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.Amount) &lt;/div&gt; &lt;div class="editor-label"&gt;@Html.LabelFor(model =&gt; model.BidTime)&lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.BidTime) &lt;/div&gt; &lt;/fieldset&gt; } </code></pre> <p>Where is it getting this metadata from and how can I stop it?</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.
 

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