Note that there are some explanatory texts on larger screens.

plurals
  1. POHtml.ValidationMessage renders on all fields, regardless if they're valid or not
    primarykey
    data
    text
    <p>My model is correctly validated. If I take a peak in the validation results during debug, I will see that everything is correct. However, <i>all</i> my validation results will show, even if only one is invalid. Again, during debug, only one field is correctly showing up in the validation results, but when my view is rendered all our displayed:</p> <pre><code>[HttpPost] public ActionResult Create(Widget widget) { if (widge.Valid) { // Save to db } retun View(widget); } </code></pre> <p>My view:</p> <pre><code>&lt;%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" Inherits="System.Web.Mvc.ViewPage&lt;Widget&gt;" %&gt; // took out a lot of html here &lt;form action="Create" method="post"&gt; &lt;input name="Widget.City" value="&lt;%= Model.City == null ? "" : Model.City%&gt;" /&gt; &lt;%= Html.ValidationMessage("Widget.City")%&gt; &lt;input name="Widget.Department" value="&lt;%= Model.Department == null ? "" : Model.Department %&gt;" /&gt; &lt;%= Html.ValidationMessage("Widget.Department")%&gt; &lt;button type="submit"&gt;Save&lt;/button&gt; &lt;/form&gt; </code></pre> <p>Let us say City and Department are set to <code>NotNull</code> in my model and I correctly put in a City, but leave Department blank. Again, it will show it is invalid on the controller, with the property Department having a problem, yet in my view I'll get "may not be null" messages for <i>both</i> properties. If I have 4 properties and 4 ValidationMessage tags in my view, even if one property is not valid ... all 4 will show. What's the deal?</p>
    singulars
    1. This table or related slice is empty.
    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. 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