aspnetcore/samples/MvcSample.Web/Views/Home/Create.cshtml

47 lines
1.4 KiB
Plaintext

@using MvcSample.Web.Models
@using Microsoft.AspNet.Mvc.ModelBinding
@model User
@{
ViewBag.Title = (Model == null) ? "Create Page" : "Edit Page";
if (ViewBag.Gift == null)
{
ViewBag.Gift = "nothing";
}
}
<div class="row">
<h2 title="@ViewBag.Title" class="@ViewBag.NullValue">@ViewBag.Title</h2>
<h3 title="Thanks" class="@ViewBag.NullValue">Thanks for @ViewBag.Gift</h3>
@if (Model == null)
{
<h4 title ="Null Model" class="@ViewBag.NullValue">Howdy, your model is null.</h4>
}
else
{
<h4 title="@Model.Name" class="@ViewBag.NullValue">Hello @Model.Name! Happy @(Model.Age)th birthday.</h4>
}
@{
var metadata = ViewData.ModelMetadata;
if (metadata != null)
{
var typeName = metadata.ModelType.Name;
var description = metadata.Description;
<p>@typeName has description '@description' and contains</p>
<ul>
@foreach (var property in metadata.Properties)
{
@PropertyListItem(property)
}
</ul>
}
}
</div>
@helper PropertyListItem(ModelMetadata property)
{
var propertyName = property.PropertyName;
var propertyTypeName = property.ModelType.Name;
<li>Property @propertyName is type @propertyTypeName and '@(property.Description ?? "no description")'</li>
}