Customizing Json from helper
Add Json to Helper Guarantee SerializerSettings
This commit is contained in:
parent
4b4034788c
commit
2a3f891878
|
|
@ -42,12 +42,20 @@ namespace MvcSample
|
||||||
|
|
||||||
public IActionResult UserJson()
|
public IActionResult UserJson()
|
||||||
{
|
{
|
||||||
return new JsonResult(new User() { Name = "User Name", Address = "Home Address" })
|
return new JsonResult(_user)
|
||||||
{
|
{
|
||||||
Encoding = Encoding.UTF8
|
Encoding = Encoding.UTF8
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IActionResult HelperUserJson()
|
||||||
|
{
|
||||||
|
JsonResult jsonResult = (JsonResult)Result.Json(_user);
|
||||||
|
jsonResult.Indent = false;
|
||||||
|
|
||||||
|
return jsonResult;
|
||||||
|
}
|
||||||
|
|
||||||
public User User()
|
public User User()
|
||||||
{
|
{
|
||||||
return _user;
|
return _user;
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
|
|
||||||
public IActionResult Json(object value)
|
public IActionResult Json(object value)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
return new JsonResult(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IActionResult View(string view, ViewData viewData)
|
public IActionResult View(string view, ViewData viewData)
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
Encoding = Encoding.UTF8;
|
Encoding = Encoding.UTF8;
|
||||||
|
|
||||||
_returnValue = returnValue;
|
_returnValue = returnValue;
|
||||||
|
_jsonSerializerSettings = CreateSerializerSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
public JsonSerializerSettings SerializerSettings
|
public JsonSerializerSettings SerializerSettings
|
||||||
|
|
@ -84,7 +85,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
JsonWriter jsonWriter = new JsonTextWriter(new StreamWriter(writeStream, effectiveEncoding));
|
JsonWriter jsonWriter = new JsonTextWriter(new StreamWriter(writeStream, effectiveEncoding));
|
||||||
if (Indent)
|
if (Indent)
|
||||||
{
|
{
|
||||||
jsonWriter.Formatting = Newtonsoft.Json.Formatting.Indented;
|
jsonWriter.Formatting = Formatting.Indented;
|
||||||
}
|
}
|
||||||
|
|
||||||
return jsonWriter;
|
return jsonWriter;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue