diff --git a/samples/MvcSample.Web/HomeController.cs b/samples/MvcSample.Web/HomeController.cs
index a0e88e211e..8b33fe2aee 100644
--- a/samples/MvcSample.Web/HomeController.cs
+++ b/samples/MvcSample.Web/HomeController.cs
@@ -11,7 +11,26 @@ namespace MvcSample.Web
}
///
- /// Action that exercises query\form based model binding.
+ /// Action that shows metadata when model is null.
+ ///
+ public IActionResult Create()
+ {
+ return View();
+ }
+
+ ///
+ /// Action that shows metadata when model is non-null.
+ ///
+ ///
+ public IActionResult Edit()
+ {
+ ViewBag.Gift = "the banana";
+ ViewData.Model = new User { Name = "Name", Address = "Address in a State", Age = 37, };
+ return View("Create");
+ }
+
+ ///
+ /// Action that exercises query\form based model binding.
///
public IActionResult SaveUser(User user)
{
@@ -55,6 +74,9 @@ namespace MvcSample.Web
return user;
}
+ ///
+ /// Action that exercises default view names.
+ ///
public IActionResult MyView()
{
return View(User());
diff --git a/samples/MvcSample.Web/Views/Home/Create.cshtml b/samples/MvcSample.Web/Views/Home/Create.cshtml
new file mode 100644
index 0000000000..a0753ee117
--- /dev/null
+++ b/samples/MvcSample.Web/Views/Home/Create.cshtml
@@ -0,0 +1,42 @@
+@using MvcSample.Web.Models
+@model User
+@{
+ string nullValue = null;
+ ViewBag.Title = (Model == null) ? "Create Page" : "Edit Page";
+ if (ViewData["Gift"] == null)
+ {
+ ViewBag.Gift = "nothing";
+ }
+}
+
+
+
@ViewBag.Title
+
Thanks for @ViewBag.Gift
+ @if (Model == null)
+ {
+
Howdy, your model is null.
+ }
+ else
+ {
+
Hello @Model.Name! Happy @Model.Age birthday.
+ }
+
+ @{
+ var metadata = ViewData.ModelMetadata;
+ if (metadata != null)
+ {
+ var typeName = metadata.ModelType.Name;
+ var description = metadata.Description;
+
@typeName has description '@description' and contains
+
+ @foreach (var property in metadata.Properties)
+ {
+ var propertyName = property.PropertyName;
+ var propertyTypeName = property.ModelType.Name;
+ var propertyDescription = property.Description;
+ - Property @propertyName has type @propertyTypeName and description '@propertyDescription'
+ }
+
+ }
+ }
+
\ No newline at end of file
diff --git a/src/Microsoft.AspNet.Mvc.Core/ActionResults/ViewResult.cs b/src/Microsoft.AspNet.Mvc.Core/ActionResults/ViewResult.cs
index b083efb127..4363711e24 100644
--- a/src/Microsoft.AspNet.Mvc.Core/ActionResults/ViewResult.cs
+++ b/src/Microsoft.AspNet.Mvc.Core/ActionResults/ViewResult.cs
@@ -33,9 +33,10 @@ namespace Microsoft.AspNet.Mvc
context.HttpContext.Response.ContentType = "text/html";
using (var writer = new StreamWriter(context.HttpContext.Response.Body, Encoding.UTF8, 1024, leaveOpen: true))
{
- var viewContext = new ViewContext(_serviceProvider, context.HttpContext, context.RouteValues, ViewData)
+ var viewContext = new ViewContext(_serviceProvider, context.HttpContext, context.RouteValues)
{
Url = new UrlHelper(context.HttpContext, context.Router, context.RouteValues),
+ ViewData = ViewData,
Writer = writer,
};
diff --git a/src/Microsoft.AspNet.Mvc.Core/Controller.cs b/src/Microsoft.AspNet.Mvc.Core/Controller.cs
index 4f0a870f72..7b76daa6ed 100644
--- a/src/Microsoft.AspNet.Mvc.Core/Controller.cs
+++ b/src/Microsoft.AspNet.Mvc.Core/Controller.cs
@@ -1,14 +1,15 @@
using Microsoft.AspNet.Abstractions;
+using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.Rendering;
namespace Microsoft.AspNet.Mvc
{
public class Controller
{
- public void Initialize(IActionResultHelper actionResultHelper)
+ public void Initialize(IActionResultHelper actionResultHelper, IModelMetadataProvider metadataProvider)
{
Result = actionResultHelper;
- ViewData = new ViewData