Short version:
How does System.Web.MVC.Controller.View(object) work?
Long version:
I need to prepend my JSON results with an arbitrary string (Unparsable Curft).
The thing I'm unsure of is how I can modify the ViewResult within the ASP.NET MVC "pipeline". I've read the MSDN docs on the subject, but I'm still unclear on how to approach this.
- How does View(Object) return a JSON string in this case?
Controller Sample
[GridAction]
public ActionResult _SelectBatchEditingGrid(int? id)
{
// GridModel is of type IEnumerable if that matters.
// More info on the GridModel type see: http://www.telerik.com/help/aspnet-mvc/t_telerik_web_mvc_gridmodel_1.html
return View(new GridModel(SessionProductRepository.All())
}
View Sample
<% Html.Telerik().ScriptRegistrar()
.OnDocumentReady(() =>
{%>
/* Protect from setter-property hacks; see https://stackoverflow.com/a/3147804/328397 */
$.ajaxSetup({
converters: {
"text cleanedjson": function(data) {
var jsonString = data.replace("throw 1; <dont be evil> ", "");
return $.parseJSON(jsonString);
} // End function
} // end conveter
}); // end ajaxsetup
- What is the best approach to prepend a string to my JSON data, via the
return View(someObject)
method?
Ideally, adding an attribute to each relevant method might be the best way to go, but I can handle this via reflection once I understand how to modify the JSON result.