显示友好的错误消息当文本盒 - ASP.NET MVC中输入HTML标记 [英] Display Friendly Error Message When Html tag is entered in a text Box- MVC ASP.NET
问题描述
我有一个文本框验证用户输入的需求。每当进入一个html标记它应该显示像友好的错误消息了同样的看法不能输入HTML标记。
I have requirement of validating user input in a text box. Whenever a html tag is entered it should display the same view with friendly error message like "Cannot enter html tags."
到目前为止,我已经试过的方法是:
The ways I have tried so far are:
- [ValidateInput(真)的控制器 - 它与错误有潜在危险的请求来了
- [ValidateInput(假)的控制器 - 它存储在数据库 - 值(我不想这样)
- 在视图模型,我把一个标签的属性
[RegularEx pression(≤([AZ] [A-Z0-9] *)\\ B〔^>] *>&LT(*);?/ \\ 1 GT;!的ErrorMessage =你输入HTML ... HTML是不是一个有效输入)]
- [ValidateInput(true)] on the Controller- It comes up with error "Potentially dangerous request"
- [ValidateInput(false)] on the Controller- It stores the value in the database-(I don't want this)
- In the view Model I placed a tag for the property
[RegularExpression ( "<([A-Z][A-Z0-9]*)\b[^>]*>(.*?)</\1>",ErrorMessage = "You have entered html…Html is not a valid input!" )]
任何一个有这个这个问题。如果是,请让我知道,怎么会有你固定的。
any one had this this issue. If yes please let me know, how have you fixed that.
感谢您
推荐答案
这是显示友好的错误消息现在的工作。我已经在帖子动作控制器添加Validateinput标签改变了一点点。
It is working now by displaying the friendly error message. I have changed a little bit by adding Validateinput tag at the Post Action controller.
我要在视图模型添加此
[AllowHtml]
[RegularExpression (@"^[^<>]*$", ErrorMessage = "You have entered html... Html is not a valid input!" )]
public string SomePropertyThatShouldNotAcceptHtml { get; set; }
在动作控制器
我要补充的标签中邮事件
I have to add the tag in the Post Event
[Validateinput(false)]
由于达林。
这篇关于显示友好的错误消息当文本盒 - ASP.NET MVC中输入HTML标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!