Custom ASP.NET MVC ActionResult classes
ASP.NET MVC provides a way for developers to extend and create custom ActionResults for controllers. Normally you return a view from a controller and the runtime goes off and hunts down the appropriate view based on the name of your action. This make sense for normal web pages but sometimes you need to build something in code or you don't want to write a view for it. In this case you can extend ActionResult, set a content type, and render the result to the output stream.
public OpenLayersActionResult MapData()
{
var myPoints = new List();
var p = new MapPoint
{
Title = "Title for point on the map",
Icon = "marker.png",
IconSize = "21,25",
LatLon = "12.9715987,77.5945627",
Description = "This is the long description for a point on the map"
};
myPoints.Add(p);
return new OpenLayersActionResult { Points = myPoints };
}
Over on GitHub you can find some sample ActionResult classes including one that replicates the built-in JsonResult. The one that will probably be most useful to someone is the OpenLayersActionResult which simplifies generation of layer data. I'm digging through various projects and building out that library with other helper code from various projects so keep an eye out for more snippets.