Asp.net mvc 4 我可以使用TextAreaFor助手作为html编辑器吗?

Asp.net mvc 4 我可以使用TextAreaFor助手作为html编辑器吗?,asp.net-mvc-4,razor-2,sql-server-2012-express,Asp.net Mvc 4,Razor 2,Sql Server 2012 Express,我可以使用TextAreaFor helper将html保存到数据库中,然后将其加载到呈现页面上吗?当然可以,但ASP.NET的请求筛选器默认不允许传入请求包含html、js等。因此,需要对模型的目标属性禁用此选项。最好的方法是使用allowtmlatAttribute标记属性 public class YourViewModel { [AllowHtml] public string description { get; set; } } 并呈现在视图中

我可以使用TextAreaFor helper将html保存到数据库中,然后将其加载到呈现页面上吗?

当然可以,但ASP.NET的请求筛选器默认不允许传入请求包含html、js等。因此,需要对模型的目标属性禁用此选项。最好的方法是使用
allowtmlatAttribute
标记属性

public class YourViewModel
{
        [AllowHtml]
        public string description { get; set; }
}  
并呈现在视图中

@Html.Raw(Model.description)
或者,您可以禁用对操作的验证请求,如

[HttpPost]
[ValidateInput(false)]
public ActionResult YourAction(YourViewModel model)
{

}

但这不是最好的解决方案。

请注意,您不能将AllowTM属性应用于控制器操作,因为它只能应用于属性。(.)