我的专业人员只是显示客户端验证错误 [英] my pro just shows client side validation errors

查看:68
本文介绍了我的专业人员只是显示客户端验证错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi
我使用@ Html.ValidationMessage(username)来检查重复的用户名。

它正在运行。但是当我有服务器端验证错误&客户端验证错误在一起,它只显示客户端错误。



@ Html.ValidationMessage(用户名)单独工作,但当我有例如电子邮件也需要错误,@ Html.ValidationMessage(用户名)没有显示,只显示电子邮件错误。



i想要点击提交按钮,两者错误可以出现。这些彼此无关。服务器和客户端不同。



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 .

    //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" })

推荐答案

你好,



你可以做一件事,请看下面解释的例子...



@ Html.TextBoxFor(m => m.username,new {@ id =group,@ class =input-block-level,

@placeholder =*输入用户名}}



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






这个当你添加必需属性时也会工作。







也适用于服务器端验证只是你必须添加这个: -



当您执行逻辑以检查重复用户时,如果找到重复用户则设置



ModeState.AddModelError(username,errorMessage)



errorMessage应该是你要设置的任何东西..(例如找到重复的用户)





如果它有用,那么请投票给这个答案。



谢谢
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


这篇关于我的专业人员只是显示客户端验证错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆