Note that there are some explanatory texts on larger screens.

plurals
  1. POModel with Required attribute doesn't show any error messages for bad user input
    primarykey
    data
    text
    <p>I have an application in which there is a user and retailer account. I want to implement validation of retailer registration form. I made a model for retailer with Required Connotation but the page still doesn't show any messages for wrong inputs. Any suggestion how I can achieve my goal. Im using Asp.net MVC </p> <pre><code>[PropertiesMustMatch("Password", "ConfirmPassword", ErrorMessage = "The password and confirmation password do not match.")] public class RegisterStore { [Required(AllowEmptyStrings = false, ErrorMessage = "Store Name is Required")] [DataType(DataType.Text)] [Display(Name = "Store Name")] public string Store_Name { get; set; } . . Similarly other properties ... . . } </code></pre> <p>The code for View is like</p> <pre><code> &lt;h2&gt;Create a Store Account&lt;/h2&gt; &lt;p&gt; Use the form below to create a new account. &lt;/p&gt; &lt;% using (Html.BeginForm()) {%&gt; &lt;%: Html.ValidationSummary(true) %&gt; &lt;fieldset&gt; &lt;legend&gt;Retailer Information&lt;/legend&gt; &lt;div class="editor-label"&gt; &lt;%: Html.LabelFor(model =&gt; model.Store_Name) %&gt; &lt;/div&gt; &lt;div class="editor-field"&gt; &lt;%: Html.TextBoxFor(model =&gt; model.Store_Name) %&gt; &lt;%: Html.ValidationMessageFor(model =&gt; model.Store_Name) %&gt; &lt;/div&gt; . ... Similar DIVs for other properties .... . . . . &lt;p&gt; &lt;input type="submit" value="Next" /&gt; &lt;/p&gt; &lt;/fieldset&gt; &lt;% } %&gt; </code></pre> <p></p> <p>The code for controller is like</p> <pre><code> [HttpPost()] public ActionResult RetailerRegisteration(RegisterStore storeModel) { //ViewData["genders"] = Genders; Debug.WriteLine("Started RetailerRegisteration"); if (string.IsNullOrEmpty(storeModel.UserName)) ModelState.AddModelError(string.Empty, "Please enter Username"); if (string.IsNullOrEmpty(storeModel.Store_Name)) ModelState.AddModelError(string.Empty, "Please enter a store name"); if (!string.IsNullOrEmpty(storeModel.Email) || !storeModel.Email.Contains("@")) ModelState.AddModelError(string.Empty, "Please enter a valid e-mail address!"); if (string.IsNullOrEmpty(storeModel.Password)) ModelState.AddModelError(string.Empty, "Please enter a Password"); if(! storeModel.Password.Equals(storeModel.ConfirmPassword)) ModelState.AddModelError(string.Empty, "The Passwords must match"); if (ModelState.IsValid) { ... Create Store Account .... } </code></pre>
    singulars
    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.
 

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