Abhilash J A

Abhilash J A

  • NA
  • 2.4k
  • 582.4k

Require validation show when page load first mvc 5

Feb 27 2017 9:02 AM
Hello everyone,
 
I am working on MVC5, 
 
1) How can I show required validation when page is first loaded as here csharp corner showing like that?
 
2) How can move error * massage to textbox right side as below image shown?
 
 
 
I have tried, 
 
CSS.
  1. /* styles for validation helpers */  
  2. .field-validation-error {  
  3.     colorred;  
  4.     font-size15px;  
  5. }  
  6.   
  7. .field-validation-valid {  
  8.     displaynone;  
  9. }  
  10.   
  11. input.input-validation-error {  
  12.     border1px solid red;  
  13. }  
  14.   
  15.   
  16. select.input-validation-error {  
  17.     border1px solid red;  
  18. }  
  19.   
  20. input[type="checkbox"].input-validation-error {  
  21.     border0 none;  
  22. }  
  23.   
  24. .validation-summary-errors {  
  25.     colorred;  
  26. }  
  27.   
  28. .validation-summary-valid {  
  29.     displaynone;  
  30. }  
  31.   
  32. /*End*/ 
Model data annotation validation.
  1. [Required]  
  2.        public string LoginName { getset; } 
And this View,
  1. @using (Html.BeginForm("GetPremiumUserReg", "UserRegister", FormMethod.Post, new { id = "frmSubmitPremUserRegFirst" }))  
  2. {  
  3.     <form role="form">  
  4.         <div class="row">  
  5.             <div class="col-xs-12 col-sm-12 col-md-12">  
  6.                 <div class="form-group">  
  7.                     @Html.ValidationMessageFor(m => m.listPartnerVM.LoginName, "*")  
  8.                     @Html.TextBoxFor(model => model.listPartnerVM.LoginName, new { @id = "email", @class = "form-control input-sm", @placeholder = "Email Address" })  
  9.   
  10.                 </div>  
  11.             </div>  
  12.         </div> 
  13.       <input type="submit" value="Submit" class="btn reg-btn btn-block">
  14.     </form>  

 Please help me...

Answers (2)