Created
April 9, 2014 11:14
-
-
Save agrcrobles/10256237 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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