diff --git a/samples/MvcSample/Home2Controller.cs b/samples/MvcSample/Home2Controller.cs index 267b56afb6..a5b9703d33 100644 --- a/samples/MvcSample/Home2Controller.cs +++ b/samples/MvcSample/Home2Controller.cs @@ -42,12 +42,20 @@ namespace MvcSample public IActionResult UserJson() { - return new JsonResult(new User() { Name = "User Name", Address = "Home Address" }) + return new JsonResult(_user) { Encoding = Encoding.UTF8 }; } + public IActionResult HelperUserJson() + { + JsonResult jsonResult = (JsonResult)Result.Json(_user); + jsonResult.Indent = false; + + return jsonResult; + } + public User User() { return _user; diff --git a/src/Microsoft.AspNet.Mvc/ActionResultHelper.cs b/src/Microsoft.AspNet.Mvc/ActionResultHelper.cs index f13b7b17cb..6d395ec330 100644 --- a/src/Microsoft.AspNet.Mvc/ActionResultHelper.cs +++ b/src/Microsoft.AspNet.Mvc/ActionResultHelper.cs @@ -32,7 +32,7 @@ namespace Microsoft.AspNet.Mvc public IActionResult Json(object value) { - throw new NotImplementedException(); + return new JsonResult(value); } public IActionResult View(string view, ViewData viewData) diff --git a/src/Microsoft.AspNet.Mvc/ActionResults/JsonResult.cs b/src/Microsoft.AspNet.Mvc/ActionResults/JsonResult.cs index 2fbeb85b65..7b64b5da80 100644 --- a/src/Microsoft.AspNet.Mvc/ActionResults/JsonResult.cs +++ b/src/Microsoft.AspNet.Mvc/ActionResults/JsonResult.cs @@ -24,6 +24,7 @@ namespace Microsoft.AspNet.Mvc Encoding = Encoding.UTF8; _returnValue = returnValue; + _jsonSerializerSettings = CreateSerializerSettings(); } public JsonSerializerSettings SerializerSettings @@ -84,7 +85,7 @@ namespace Microsoft.AspNet.Mvc JsonWriter jsonWriter = new JsonTextWriter(new StreamWriter(writeStream, effectiveEncoding)); if (Indent) { - jsonWriter.Formatting = Newtonsoft.Json.Formatting.Indented; + jsonWriter.Formatting = Formatting.Indented; } return jsonWriter;