0

Can I use a TextAreaFor helper to save html to a database and then load it onto a page where it is rendered?

4

1 回答 1

1

Sure you can, but ASP.NET's request filter doesn't allow an incoming request to contain html, js, etc. by default. So you need to disable this option for the target property of your model. The best way to do this is to mark the property with an AllowHtmlAttribute.

public class YourViewModel
{
        [AllowHtml]
        public string description { get; set; }
}  

and render in view

@Html.Raw(Model.description)

Alternatively you can disable the validate request for the action like

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

}

but it is not best solution.

于 2013-07-07T12:22:19.183 回答