How to show error on label control in MVC 3

Posted by Sumit.Bundiwal under ASP.NET on 7/30/2012 | Points: 10 | Views : 1444 | Status : [Member] | Replies : 2
I want to show error on label control of index page using controller .Ex i write wrong user name and password in login page then in a label control i want to show error "Username or password does not match".(in MVC3 form)







Thanks in advanced

sumit bundiwal


Responses

Posted by: Jayakumars on: 9/27/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

try this

@Html.ValidationSummary(true, "Login was unsuccessful. Please correct the errors and try again.")

@using (Html.BeginForm()) {
<div>
<fieldset>
<legend>Account Information</legend>

<div class="editor-label">
@Html.LabelFor(m => m.UserName)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.UserName)
@Html.ValidationMessageFor(m => m.UserName)
</div>

<div class="editor-label">
@Html.LabelFor(m => m.Password)
</div>
<div class="editor-field">
@Html.PasswordFor(m => m.Password)
@Html.ValidationMessageFor(m => m.Password)
</div>

<div class="editor-label">
@Html.CheckBoxFor(m => m.RememberMe)
@Html.LabelFor(m => m.RememberMe)
</div>

<p>
<input type="submit" value="Log On" />
</p>
</fieldset>
</div>
}



Mark as Answer if its helpful to you

Sumit.Bundiwal, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 9/27/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi
Please mark as answer if it helpful to you.

Mark as Answer if its helpful to you

Sumit.Bundiwal, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response