Asp.Net 4.0 MVC 3: Publish HTML

When I publish the contents of a text field containing an html code, I get a message about dangerous content. I read how to configure the behavior of old 2.0, but it does not work for me, and I would prefer to have a clean solution. I'm probably not the only person who needs to host html, so I'm curious that I could not find a solution to disable this behavior. Any hint on how to solve this problem correctly?

+3
source share
2 answers

For your input model, you can define:

public class FormViewModel
{
    [AllowHtml]
    public string Content { get; set; }
}

Where Contentis your respective field:

@Html.EditorFor(m => m.Content)
+5
source

Have you added the Validate Input attribute to the controller method?

[ValidateInput(false)]

, web.config, -, mvc, , , .

<system.web>
    <httpRuntime requestValidationMode="2.0" />
</system.web>

<system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
</system.webServer>
+1

All Articles