We are using the mixed mode (aspx and mvc) but I developed all my widgets in MVC.
For one widget I had the request to show statistical data in a chart and the request to the datasource (an external web server) takes about 2-3 seconds. I didn't want to let the user feel that the whole page is not responding just because of this data request and so I decided to to an ajax request in the background.
With jQuery this is an easy task, but I was not able to return the json data to the client. I returned a JsonResult on the Controller but Sitefinity always injected somehow the master layout of the page and therefore it was invalid json when it was received by the client.
Fortunately I found a solution to this problem:
public ActionResult GetAjaxData() { Response.ClearHeaders(); Response.AddHeader("Content-type", "text/json"); Response.AddHeader("Content-type", "application/json"); Response.ClearContent();
//here you obtain your list of objects
ListmyResult = new List ();
Response.Write(myResult.ToJson()); Response.End(); return new EmptyResult();
}
4 comments:
Very nice solution, Manfred. So now, you don't have to actually write a new route as I was doing before. I like your solution.
Sitefinity Winnipeg
kul page
SITEFINITY IS ONE BIG PILE OF SHIT!
Post a Comment