My controller code:
public async Task<ActionResult> GetHtml(int id)
{
var myModel = await db.Models.FindAsync(id);
return Json(new { jsonData = myModel.MyHtml }, JsonRequestBehavior.AllowGet);
}
My View code:
$('#MyDropDownList').on('change', function() {
var myModelId = $(this).val();
var urlGetMyHtml = '@Url.Action("GetHtml", "MyHtmlController")';
$.getJSON(
urlGetMyHtml,
{ id: myModelId },
function(jsonData) {
console.log(jsonData);
$('textarea#MyHtmlArea').val(jsonData);
});
});
The success function never executes... I checked Fiddler and Firebug, and the code runs successfuly on controller and delivers on client. But then the function is not executed...
Researching, I discovered the success function executes only if we have a valid JSON, then my guess is that my JSON contains HTML code (its for an WYSIWYG editor, like tinymce) getJSON says it is not valid...
So, whats the correct way to send my html snippet using ajax?