AllowHtml attribute not working

后端 未结 4 738
粉色の甜心
粉色の甜心 2020-12-06 07:38

I have a model with this property:

     [AllowHtml]
     [DisplayName(\"Widget for Table\")]
     [StringLength(1000, ErrorMessage = \"Maximum chars 1000\")]         


        
相关标签:
4条回答
  • 2020-12-06 08:06

    I had the same problem. My model class is named "GeneralContent" and has the property "Content". In my action method i used attribute like this:

    public ActionResult Update(GeneralContent content)

    when i renamed content argument to cnt, everything works well. I think MVC is confused when some attribude of model class has the same name as the argument in action method.

    0 讨论(0)
  • 2020-12-06 08:15

    I also had this issue. I could not get a model property marked with [AllowHtml] to actually allow HTML, and instead encountered the same error you describe. My solution ended up being to mark the Controller action that accepts the posted model with the [ValidateInput(false)] attribute.

    0 讨论(0)
  • 2020-12-06 08:20

    The way you are using AllowHtml should work. Make sure that you are not accessing the HttpRequest.Form collection anywhere else in your code (controller, filter, etc) as this will trigger ASP.NET Request Validation and the error you are seeing. If you do want access to that variable then you should access it via the following code.

    using System.Web.Helpers;
    
    HttpRequestBase request = ..  // the request object
    request.Unvalidated().Form;
    
    0 讨论(0)
  • 2020-12-06 08:21

    I get the same problem and i solve it with the help of this post.

    If you are on .net 4.0 make sure you add this in your web.config

    <httpRuntime requestValidationMode="2.0" />
    

    Inside the <system.web> tags

    0 讨论(0)
提交回复
热议问题