1

I have a form where the user can enter some html content to the HtmlContent property. I use AllowHtml attribute to allow for that kind of content:

[AllowHtml]
public string HtmlContent { get;set; }

When user submits the form and it's valid, everything is ok. But if there are thrown some exceptions in controller during saving, even if there is a try...catch statement:

public void Save(Model viewModel)
{
    try
    {
        // let's say that an exception is thrown here
        Save();
    }
    catch(Exception exception)
    { 
        // I should be able to catch here the exception that was thrown above
        ModelState.AddModelError("", "Error");        
    }

    return View();
}

I always receive the same exception related to my HtmlContent property:

A potentially dangerous value was detected from the client

Which is wrong, because I put AllowHtml attribute.

cryss
  • 4,130
  • 1
  • 29
  • 34
  • use this link http://stackoverflow.com/questions/81991/a-potentially-dangerous-request-form-value-was-detected-from-the-client – Vishvadeep singh Jul 29 '14 at 10:46
  • What are other fields? Are they taking html as well? – trailmax Jul 29 '14 at 10:46
  • @trailmax No, only that one particular property is for html content. – cryss Jul 29 '14 at 10:48
  • What does `Save()` do? `[AllowHtml]` should let html content to be submitted and it works, because you get data through your controller, otherwise it would explode before reaching your controller. So the problem with `Save()` method that for some reason ignores `[AllowHtml]` – trailmax Jul 29 '14 at 10:52

0 Answers0