Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
hi i use @Html.ValidationMessage("username") to check duplicate username .
and it is working. but when i have serverside validation error & clientside validation error together , it just shows clientside error .

@Html.ValidationMessage("username") alone works , but when i have forexample email required error too , @Html.ValidationMessage("username") doesn't show and just email error is shows.

i wanna when i click submit button , both error can to appear. these are not related to each other . server and client are diffrent .

C#
    //Client
@Html.TextBoxFor(m => m.email, new { @class = "group", @placeholder = "*  enter email" })
 @Html.ValidationMessageFor(model => model.email)


   //Server
  @Html.ValidationMessage("username")
  @Html.TextBoxFor(m => m.username, new {@id="group" , @class = "input-block-level", @placeholder = "* enter username" })
Posted
Updated 7-Aug-13 9:46am
v2
Comments
Sergey Alexandrovich Kryukov 7-Aug-13 17:04pm    
What is "pro"? :-)
—SA

1 solution

Hello,

you can do one thing, please see below explained example...

@Html.TextBoxFor(m => m.username, new {@id="group" , @class = "input-block-level",
@placeholder = "* enter username" })

@Html.ValidationMessageFor(m => m.username)



This will also work when you add Required attribute .

And

Also work for server side validation just you have to add this :-

when you excute your logic to check duplicate user, and if it finds duplicate user then set

ModeState.AddModelError("username",errorMessage)

errorMessage should be whatever you want to set.. (e.g "duplicate user found")


if it is useful then please vote for this answer.

Thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900