Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.Net 4.0 MVC 3: Post html code

When posting textbox content which contains html code, I get an error regarding possible dangerous content. I read how to configure the old 2.0 behaviour, but it does not work for me and I would prefer to have a clean solution. I'm probably not the only person which needs to post html, so I wonder that I could not found a solution for disabling this behaviour. Any hint what's the correct way to solve this problem?

like image 536
Achim Avatar asked Apr 18 '26 02:04

Achim


2 Answers

For your input model, you can define:

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

Where Content is your appropriate field:

@Html.EditorFor(m => m.Content)
like image 126
Matthew Abbott Avatar answered Apr 21 '26 02:04

Matthew Abbott


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

[ValidateInput(false)]

I think you only need these in your web.config if using web forms as well as mvc, but might be worth trying.

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

<system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
</system.webServer>
like image 34
Nick Avatar answered Apr 21 '26 00:04

Nick