diff --git a/src/Microsoft.AspNet.Mvc.Core/ViewComponents/JsonViewComponentResult.cs b/src/Microsoft.AspNet.Mvc.Core/ViewComponents/JsonViewComponentResult.cs
index 895e85e695..688a36b917 100644
--- a/src/Microsoft.AspNet.Mvc.Core/ViewComponents/JsonViewComponentResult.cs
+++ b/src/Microsoft.AspNet.Mvc.Core/ViewComponents/JsonViewComponentResult.cs
@@ -4,6 +4,7 @@
using System.Threading.Tasks;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal;
+using Newtonsoft.Json;
namespace Microsoft.AspNet.Mvc
{
@@ -17,8 +18,19 @@ namespace Microsoft.AspNet.Mvc
///
/// The value to format as JSON text.
public JsonViewComponentResult(object value)
+ : this(value, formatter: null)
+ {
+ }
+
+ ///
+ /// Initializes a new .
+ ///
+ /// The value to format as JSON text.
+ /// The to be used by
+ /// the formatter.
+ public JsonViewComponentResult(object value, [NotNull] JsonSerializerSettings serializerSettings)
+ : this(value, new JsonOutputFormatter(serializerSettings))
{
- Value = value;
}
///
diff --git a/src/Microsoft.AspNet.Mvc.Core/ViewComponents/ViewComponent.cs b/src/Microsoft.AspNet.Mvc.Core/ViewComponents/ViewComponent.cs
index 0e1184ea0a..21731b2819 100644
--- a/src/Microsoft.AspNet.Mvc.Core/ViewComponents/ViewComponent.cs
+++ b/src/Microsoft.AspNet.Mvc.Core/ViewComponents/ViewComponent.cs
@@ -8,6 +8,7 @@ using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.Internal;
+using Newtonsoft.Json;
namespace Microsoft.AspNet.Mvc
{
@@ -167,11 +168,25 @@ namespace Microsoft.AspNet.Mvc
///
/// The value to output in JSON text.
/// A .
- public JsonViewComponentResult Json([NotNull] object value)
+ public JsonViewComponentResult Json(object value)
{
return new JsonViewComponentResult(value);
}
+ ///
+ /// Returns a result which will render JSON text.
+ ///
+ /// The value to output in JSON text.
+ /// The to be used by
+ /// the formatter.
+ /// A .
+ /// Callers should cache an instance of to avoid
+ /// recreating cached data with each call.
+ public JsonViewComponentResult Json(object value, [NotNull] JsonSerializerSettings serializerSettings)
+ {
+ return new JsonViewComponentResult(value, serializerSettings);
+ }
+
///
/// Returns a result which will render the partial view with name "Default".
///
diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ControllerTests.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ControllerTests.cs
index e60daa5f6d..813647ac56 100644
--- a/test/Microsoft.AspNet.Mvc.Core.Test/ControllerTests.cs
+++ b/test/Microsoft.AspNet.Mvc.Core.Test/ControllerTests.cs
@@ -1074,6 +1074,33 @@ namespace Microsoft.AspNet.Mvc.Test
Times.Once());
}
+ [Fact]
+ public void Controller_JsonWithParameterValueAndSerializerSettings_IDisposableObject_RegistersForDispose()
+ {
+ // Arrange
+ var mockHttpContext = new Mock();
+ mockHttpContext.Setup(x => x.Response.OnResponseCompleted(It.IsAny>(), It.IsAny