Reputation: 2488
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.
Upvotes: 0
Views: 2106
Reputation: 919
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 <
and >
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
Upvotes: 1