diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewResult.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewResult.cs index 566d2f0f20..ce6f04033f 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewResult.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewResult.cs @@ -28,6 +28,11 @@ namespace Microsoft.AspNet.Mvc /// public string ViewName { get; set; } + /// + /// Gets the view data model. + /// + public object Model => ViewData?.Model; + /// /// Gets or sets the for this result. /// diff --git a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewResultTest.cs b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewResultTest.cs index 8ba70f2692..dba0af8c3a 100644 --- a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewResultTest.cs +++ b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewResultTest.cs @@ -24,6 +24,33 @@ namespace Microsoft.AspNet.Mvc // and ViewExecutorTest for more comprehensive tests. public class ViewResultTest { + [Fact] + public void Model_NullWhenViewDataIsNull() + { + // Arrange + var viewResult = new ViewResult(); + + // Act & Assert + Assert.Null(viewResult.Model); + } + + [Fact] + public void Model_ExposesViewDataModel() + { + // Arrange + var customModel = new object(); + var viewResult = new ViewResult + { + ViewData = new ViewDataDictionary(new EmptyModelMetadataProvider()) + { + Model = customModel + }, + }; + + // Act & Assert + Assert.Same(customModel, viewResult.Model); + } + [Fact] public async Task ExecuteResultAsync_Throws_IfViewCouldNotBeFound_MessageUsesGetViewLocations() {