【发布时间】:2011-04-13 10:36:38
【问题描述】:
我正在尝试向我的控制器操作提交表单,其中一个表单字段包含 HTML 标记,例如 <p> <ul>
我已经添加了
<httpRuntime requestValidationMode="2.0"/>
和
<pages
validateRequest="false"
</pages>
在我的web.config,还有
我已经添加了
[ValidateInput(false)] 我的控制器操作
但是当我提交表单时,description 字段包含 HTML 标记,它会给出以下错误:
A potentially dangerous Request.Form value was detected from the client (desc="<ul><li>Comments: Th...").
我应该/可以做什么,在此先感谢...
我正在使用 VS 2010、MVC、实体框架
编辑
这是视图端代码
<% using (Html.BeginForm("UpdateProductVariant", "home", new { Id = Model.productVariant.ProductVariantId }, FormMethod.Post))
{%>
<table>
<tr>
<td>Name:</td>
<td><%: Html.TextArea("ProductVariantName", Model.product.Name)%></td>
</tr>
<tr>
<td>Description:</td>
<td><%= Html.TextArea("desc",Model.productVariant.Description)%></td>
</tr>
控制器端
[ValidateInput(false)]
public ActionResult UpdateProductVariant(int id, FormCollection collection, bool pub, bool del, decimal hprice)
{
【问题讨论】:
-
它可能与您提到的问题重复,但该问题中提出的解决方案并不能解决我的问题...
-
尝试使用 Server.HtmlEncode 获取相关值
-
我错了,您的问题将保持开放。 :)
-
我相信当前请求上下文中的所有动作都应该有 [ValidateInput(false)] 属性
标签: c# asp.net-mvc entity-framework html-helper form-submit