I like to customize the error information, such as adding an incorrect small icon and creating an incorrect style. I found that the default @ Html. ValidationMessage cannot reach my goal.
Create Model:
Public ClassLogin_Index
{
[DisplayName ("Logon account")]
[Required (ErrorMessage= "Logon account cannot be blank")]
Public StringUser_name {Set;Get;}
[DisplayName ("Logon Password")]
[Required (ErrorMessage= "The logon password cannot be blank.")]
Public StringUser_password {Set;Get;}
}
Create HTML:
@ Using (Html. BeginForm ())
{
<FieldsetClass= "Form">
@ Html. ValidationImage ()
<P>
@ Html. LabelFor (m => m. user_name)
@ Html. TextBoxFor (m => m. user_name)
</P>
<P>
@ Html. LabelFor (m => m. user_password)
@ Html. TextBoxFor (m => m. user_password)
</P>
<ButtonType= "Submit"Class= "Positive"Name= "Submit">
<ImgSrc= "/Content/images/key.png"Alt= "Announcement" />Login</Button>
<UlId= "Forgottenpassword">
<LiClass= "Boldtext">|</Li>
<Li> <AHref= "/Login/forgot">What should I do if I forget my password?</A> </Li>
</Ul>
</Fieldset>
}
Action operation:
/// <Summary>
///User Logon Process
/// </Summary>
/// <Returns> </returns>
[HttpPost]
PublicActionResult Index (Login_Index model)
{
If(ModelState. IsValid)
ReturnRedirectToAction ("Index","Home");
Else
{
ReturnView ();
}
}
Extended HtmlHelper: