Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom validation error not displayed
    primarykey
    data
    text
    <p>I have an MVC 3 application and am trying to display a custom validation error. The normal validation errors that are generated by the model, i.e. Required, are displayed on the page. Now I am checking if a user exists and if so, adding a error message:</p> <pre><code>if (userExists) ModelState.AddModelError("UserName", UserManagementResources.UserAlreadyExistsText); return View(model); </code></pre> <p>On the view I have a validation summary and a Html.ValidationMessage("UserName"), but neither one is displaying the error. I have used this successfully on other pages. The only difference with this page I can see is, that it uses the RequiredIf validator scripts. <a href="http://blogs.msdn.com/b/simonince/archive/2011/02/04/conditional-validation-in-asp-net-mvc-3.aspx" rel="nofollow">http://blogs.msdn.com/b/simonince/archive/2011/02/04/conditional-validation-in-asp-net-mvc-3.aspx</a> </p> <p>Any ideas how to solve this problem are appreciated. Thanks.</p> <hr> <p>Edit</p> <p>I am returning the validation message through the Remote validation. If I look what the network is doing, it's returning the error message, but it is still not displayed on the view.</p> <pre><code>[Required] [DataType(DataType.EmailAddress)] [Remote("IsUserAvailable", "Validation", ErrorMessage = "Ein Benutzer mit dieser Email existiert bereits.")] [Display(Name = Resources.EmailText, ResourceType = typeof(Resources))] public string Email { get { return User.Email; } set { User.Email = value; } } </code></pre> <p>The View:</p> <pre><code>@Html.LabelFor(u =&gt; u.Email, Resources.Email + " (Login) *") @Html.EditorFor(u =&gt; u.Email) @Html.ValidationMessageFor(u =&gt; u.Email) &lt;br clear="all" /&gt; </code></pre> <p>The Remote Validation Controller:</p> <pre><code>public class ValidationController : Controller { public JsonResult IsUserAvailable(string Email) { bool userExists; using (var userModel = new UserManagementModel()) { userExists = userModel.UserExists(Email); } if(userExists) return Json(UserManagementResources.UserAlreadyExists, JsonRequestBehavior.AllowGet); else return Json(true, JsonRequestBehavior.AllowGet); } } </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