Use Json result constructor only from the Action result helper.
Names to be changed, as they don't make much sense at the moment. Keeping them the same for diffing purposes
This commit is contained in:
parent
312b4c5fb5
commit
764e5f890d
|
|
@ -42,15 +42,7 @@ namespace MvcSample
|
||||||
|
|
||||||
public IActionResult UserJson()
|
public IActionResult UserJson()
|
||||||
{
|
{
|
||||||
return new JsonResult(_user)
|
var jsonResult = Result.Json(_user);
|
||||||
{
|
|
||||||
Encoding = Encoding.UTF8
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public IActionResult HelperUserJson()
|
|
||||||
{
|
|
||||||
JsonResult jsonResult = (JsonResult)Result.Json(_user);
|
|
||||||
jsonResult.Indent = false;
|
jsonResult.Indent = false;
|
||||||
|
|
||||||
return jsonResult;
|
return jsonResult;
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,13 @@ namespace Microsoft.AspNet.Mvc
|
||||||
{
|
{
|
||||||
public class ActionResultFactory : IActionResultFactory
|
public class ActionResultFactory : IActionResultFactory
|
||||||
{
|
{
|
||||||
|
private readonly IActionResultHelper _result;
|
||||||
|
|
||||||
|
public ActionResultFactory(IActionResultHelper result)
|
||||||
|
{
|
||||||
|
_result = result;
|
||||||
|
}
|
||||||
|
|
||||||
public IActionResult CreateActionResult(Type declaredReturnType, object actionReturnValue, RequestContext requestContext)
|
public IActionResult CreateActionResult(Type declaredReturnType, object actionReturnValue, RequestContext requestContext)
|
||||||
{
|
{
|
||||||
// optimize common path
|
// optimize common path
|
||||||
|
|
@ -45,7 +52,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return new JsonResult(actionReturnValue);
|
return _result.Json(actionReturnValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public IActionResult Json(object value)
|
public IJsonResult Json(object value)
|
||||||
{
|
{
|
||||||
return new JsonResult(value);
|
return new JsonResult(value);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNet.Mvc
|
||||||
|
{
|
||||||
|
public interface IJsonResult : IActionResult
|
||||||
|
{
|
||||||
|
Encoding Encoding { get; set; }
|
||||||
|
bool Indent { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -7,7 +7,7 @@ using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc
|
namespace Microsoft.AspNet.Mvc
|
||||||
{
|
{
|
||||||
public class JsonResult : IActionResult
|
public class JsonResult : IJsonResult
|
||||||
{
|
{
|
||||||
private readonly object _returnValue;
|
private readonly object _returnValue;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
{
|
{
|
||||||
IActionResult Content(string value);
|
IActionResult Content(string value);
|
||||||
IActionResult Content(string value, string contentType);
|
IActionResult Content(string value, string contentType);
|
||||||
IActionResult Json(object value);
|
IJsonResult Json(object value);
|
||||||
IActionResult View(string view, ViewData viewData);
|
IActionResult View(string view, ViewData viewData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue