小编car*_* gu的帖子

MVC ASP.NET MVC3 AllowHtml属性不起作用?

问题很简单:

假设你有一个名为Person的模型

public class Person
{

       public int PersonID {get; set;}

       public string Name {get; set;}

       [AllowHtml] // Allow html in Intro property
       public string Intro {get; set;}

       [ScaffoldColumn(false)]
       public string ComplicatedValue {get; set;}

}
Run Code Online (Sandbox Code Playgroud)

在控制器的"创建"操作中

[HttpPost]
public ActionResult Create(Person o, FormCollection collection)
{

// whatever code here;

}
Run Code Online (Sandbox Code Playgroud)

如果你运行它,

  1. 为Intro输入纯文本,没有问题发生.
  2. 为Intro输入html内容,无论你如何设置你的配置文件,它都会告诉"潜在的危险......"

我找到了这个问题的原因.

如果将功能更改为

public ActionResult Create(Person o) // Get rid of the *FormCollection collection*
{

// whatever code here;

}
Run Code Online (Sandbox Code Playgroud)

这将消除"潜在的危险"错误.

但我的问题是,对于我的应用程序,我必须在Create Action方法中使用辅助参数FormCollection集合,因为我需要使用一些其他控件值和服务器变量来为ComplicatedValue属性分配计算值.

如果ASP.NET …

asp.net-mvc-3

7
推荐指数
2
解决办法
5021
查看次数

标签 统计

asp.net-mvc-3 ×1