From b8d58133c327fa9f96b24738a0a142b926acc4b9 Mon Sep 17 00:00:00 2001 From: ryanbrandenburg Date: Thu, 12 Nov 2015 10:27:03 -0800 Subject: [PATCH] * Add NoContent Factory to Controller --- src/Microsoft.AspNet.Mvc.ViewFeatures/Controller.cs | 11 +++++++++++ .../ControllerTest.cs | 13 +++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Controller.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Controller.cs index 4ca6389f54..ace64731b4 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Controller.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Controller.cs @@ -508,6 +508,17 @@ namespace Microsoft.AspNet.Mvc return result; } + + /// + /// Creates a object that produces an empty No Content (204) response. + /// + /// The created object for the response. + [NonAction] + public virtual NoContentResult NoContent() + { + return new NoContentResult(); + } + /// /// Creates a object that serializes the specified object /// to JSON. diff --git a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ControllerTest.cs b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ControllerTest.cs index f509bf50ec..79d43f9168 100644 --- a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ControllerTest.cs +++ b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ControllerTest.cs @@ -1055,6 +1055,19 @@ namespace Microsoft.AspNet.Mvc.Test Assert.Same(model, actualViewResult.ViewData.Model); } + [Fact] + public void Controller_NoContent() + { + // Arrange + var controller = new TestableController(); + + // Act + var result = controller.NoContent(); + + // Assert + Assert.Equal(StatusCodes.Status204NoContent, result.StatusCode); + } + [Fact] public void Controller_Content_WithParameterContentString_SetsResultContent() {