开发者

Asp.Net 4.0 MVC 3: Post html code

开发者 https://www.devze.com 2023-03-11 00:56 出处:网络
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 prefe

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?


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)


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>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号