Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET MVC Html.ValidationSummary(true) does not display model errors
    primarykey
    data
    text
    <p>I have some problem with Html.ValidationSummary. I don't want to display property errors in ValidationSummary. And when I set Html.ValidationSummary(true) it does not display error messages from ModelState. When there is some Exception in controller action on string</p> <pre><code>MembersManager.RegisterMember(member); </code></pre> <p>catch section adds an error to the ModelState:</p> <pre><code>ModelState.AddModelError("error", ex.Message); </code></pre> <p>But ValidationSummary does not display this error message. When I set Html.ValidationSummary(false) all messages are displaying, but I don't want to display property errors. How can I fix this problem?</p> <p>Here is the code I'm using:</p> <p>Model:</p> <pre><code>public class Member { [Required(ErrorMessage = "*")] [DisplayName("Login:")] public string Login { get; set; } [Required(ErrorMessage = "*")] [DataType(DataType.Password)] [DisplayName("Password:")] public string Password { get; set; } [Required(ErrorMessage = "*")] [DataType(DataType.Password)] [DisplayName("Confirm Password:")] public string ConfirmPassword { get; set; } } </code></pre> <p>Controller:</p> <pre><code>[HttpPost] public ActionResult Register(Member member) { try { if (!ModelState.IsValid) return View(); MembersManager.RegisterMember(member); } catch (Exception ex) { ModelState.AddModelError("error", ex.Message); return View(member); } } </code></pre> <p>View:</p> <pre><code>&lt;% using (Html.BeginForm("Register", "Members", FormMethod.Post, new { enctype = "multipart/form-data" })) {%&gt; &lt;p&gt; &lt;%= Html.LabelFor(model =&gt; model.Login)%&gt; &lt;%= Html.TextBoxFor(model =&gt; model.Login)%&gt; &lt;%= Html.ValidationMessageFor(model =&gt; model.Login)%&gt; &lt;/p&gt; &lt;p&gt; &lt;%= Html.LabelFor(model =&gt; model.Password)%&gt; &lt;%= Html.PasswordFor(model =&gt; model.Password)%&gt; &lt;%= Html.ValidationMessageFor(model =&gt; model.Password)%&gt; &lt;/p&gt; &lt;p&gt; &lt;%= Html.LabelFor(model =&gt; model.ConfirmPassword)%&gt; &lt;%= Html.PasswordFor(model =&gt; model.ConfirmPassword)%&gt; &lt;%= Html.ValidationMessageFor(model =&gt; model.ConfirmPassword)%&gt; &lt;/p&gt; &lt;div&gt; &lt;input type="submit" value="Create" /&gt; &lt;/div&gt; &lt;%= Html.ValidationSummary(true)%&gt; &lt;% } %&gt; </code></pre>
    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.
 

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