Sky Lin wrote:
Hi Matteo,
I met the same issues, the action return the string + HTML.
Have you find the way to fix it?
Thanks
Sky
Hi Sky Lin,
here you can see that the JsonResult is an unsupported MVC features of DNN8.
So I've used a method not very elegant:
In my controller I return an object as JsonResult:
return new JsonResult()
{
Data = new
{
MyValue= myValue,
Error = false
},
JsonRequestBehavior = JsonRequestBehavior.AllowGet
};
In the view I intercept the error (the string+HTML throw a client "parsing error") and I handle the result in this way:
$.ajax({
url: '@Url.Action("MyAction", "MyController")',
type: 'POST',
cache: false,
data: myData,
headers: {
"ModuleId": ModuleId,
"TabId": TabId,
"RequestVerificationToken": rvtoken
},
dataType:"json",
error: function(jqXHR, textStatus, errorThrown){
actionResponse = jqXHR.responseText.substring(0, jqXHR.responseText.indexOf("<!DOCTYPE html>"));
if (actionResponse)
{
data = JSON.parse(actionResponse);
if (data && data.Error == false)
{
var myValue = data.MyValue;
}
}
});
I hope this can help you...
Matteo