Skip to content

Instantly share code, notes, and snippets.

@agrcrobles
Created April 9, 2014 11:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agrcrobles/10256237 to your computer and use it in GitHub Desktop.
Save agrcrobles/10256237 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Echk.Web.Mvc
{
/// <summary>
/// ale's approach
/// </summary>
public class JsonDynamicResult : System.Web.Mvc.ActionResult
{
public dynamic DynamicViewData { get; set; }
// Summary:
// Gets or sets the content encoding.
//
// Returns:
// The content encoding.
public System.Text.Encoding ContentEncoding { get; set; }
//
// Summary:
// Gets or sets the type of the content.
//
// Returns:
// The type of the content.
public string ContentType { get; set; }
//
// Summary:
// Gets or sets a value that indicates whether HTTP GET requests from the client
// are allowed.
//
// Returns:
// A value that indicates whether HTTP GET requests from the client are allowed.
public System.Web.Mvc.JsonRequestBehavior JsonRequestBehavior { get; set; }
public override void ExecuteResult(System.Web.Mvc.ControllerContext context)
{
if (context == null)
throw new ArgumentNullException("context");
var response = context.HttpContext.Response;
response.ContentType = !string.IsNullOrEmpty(ContentType) ? ContentType : "application/json";
if (ContentEncoding != null)
response.ContentEncoding = ContentEncoding;
if (DynamicViewData == null)
return;
response.Write(new Echk.Framework.Json.WJsonSerializer().Serialize(DynamicViewData));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment