有没有一种方法,让用户提交HTML内容,同时还使模型验证? [英] Is there a way to allow a user to submit html content while still enabling model validation?

查看:159
本文介绍了有没有一种方法,让用户提交HTML内容,同时还使模型验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要允许用户提交包含在他们的文本输入框HTML表单值。这是一个内部应用程序面临所以它是相当安全的这样做。我已成功使用了

I need to allow users to submit a form value containing html in their text inputs. This is an internally-facing application so it's reasonably safe to do so. I have succesfully used the

[ValidateInput(false)] 

这是有问题的方法,但这种抑制的所有的模型验证有问题的方法/视图模型,但我只希望允许HTML中的有一个的的属性文本框和不一定愿意写我自己的后卫子句中相同的方法/视图模型,当我可以将preFER继续使用数据注释为所有其他属性在视图模型每隔一段模型验证。
  这太糟糕了,我不能应用[ValidateInput(假)只有我的视图模型中的一个属性。我会认为我需要重写MVC的默认模型验证,但我无法找到如何做到这一点的任何文档。每个搜索产生的结果只说明怎么写我自己的自定义验证属​​性,这是不正确的,我试图解决这个问题。
谢谢!

attribute on the method in question, but this inhibits all model validation for the method/view model in question, but I only want to allow html in one of the TextBoxes and do not necessarily wish to write my own guard clauses for every other piece of model validation in the same method/view model, when I could would prefer to continue using Data Annotations for all of the other properties in the view model. It's too bad I cannot apply the [ValidateInput(false)] to only a single property of my viewmodel. I would assume that I need to override mvc's default model validation, but I cannot find any documentation on how to do so. Every search yields results describing only how to write my own custom validation attributes, which isn't correct for the problem I'm trying to solve. Thanks!

推荐答案

您将不得不您aplication升级到ASP.NET MVC 3,有你有AllowHtmlAttribute,你可以用它来对财产级别禁用输入验证。 ASP.NET MVC 3与ASP.NET MVC 2落后的密实所以升级应该很容易。

You would have to upgrade your aplication to ASP.NET MVC 3. There you have AllowHtmlAttribute, which you can use to disable input validation on property level. ASP.NET MVC 3 is backward compactible with ASP.NET MVC 2 so the upgrade should be easy.

这篇关于有没有一种方法,让用户提交HTML内容,同时还使模型验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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