[英]Change text of ValidationSummary C# razor MVC
I am using ValidationSummary
to show errors after submit login action on my login page. 在登录页面上提交登录操作后,我正在使用ValidationSummary
显示错误。
There are two different errors to show. 有两个不同的错误要显示。
1) Username and password invalid 1)用户名和密码无效
or 要么
2) You are not allowed to access this feature 2)您无权使用此功能
The thing is that I want to change the text of the ValidationSummary
. 问题是我想更改ValidationSummary
的文本。 I don't want to add errors as bullet points (this is done adding errors to ModelState
using ModelState.AddModelError
). 我不想添加错误作为要点(通过使用ModelState.AddModelError
将错误添加到ModelState
可以完成)。
How can I achieve this? 我该如何实现? Change the error message of the ValidationSummary
? 更改ValidationSummary
的错误消息?
Thanks! 谢谢!
The simplest solution is that you can return message in json in your post method. 最简单的解决方案是您可以在post方法中以json返回消息。 and display that message in span instead of validation summary. 并跨度显示该消息,而不是验证摘要。
For example 例如
return Json(new object[] { false, "Invalid user name or password" },
JsonRequestBehavior.AllowGet);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.