0

I'm using CLEditor to provide an html editor for my app user, CLEditor use an text area to maintain the generated html, I'm using jquery ajax to save the html:

$(".btnSave").click(function () {
    var description = $(this).find("textarea[name='Description']").val();
    $.ajax({
            url: "/Product/SaveDescription",
            data: { description: description },
            success: function (result) {
                alert("Saved successfully.");
            },
            error: function (xhr, state, msg) {
                alert(msg);
            }
    });
});

but when my variable (description) contains html tags the action won't trigger , and I get an error (internal server error).

This is my action method:

public void SaveDescription(string description)
{
     //save the description
}   

As you can see I'm not using MVC model binder which need AllowHtml attribute to allow html, so what is the problem?

Thanks for your help.

VahidNaderi
  • 2,448
  • 1
  • 23
  • 35

1 Answers1

1

My first guess would be you're not allowed to post HTML encoded content to the action; therefor also the question: Which Server Error do you get when posting?

You can turn off the ValidateRequest (for the page or the site), but I doubt you'd want that for that entire site; you could also try to replace the < and > in the description to &lt; and &gt; before posting and undo that replace in the SaveDescription tag (not really a desired solution).

Also take a look at these answers: Allow User to input HTML in ASP.NET MVC - ValidateInput or AllowHtml

Community
  • 1
  • 1
Leon
  • 919
  • 6
  • 21