87 lines
2.8 KiB
Plaintext
87 lines
2.8 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>
|
|
|
|
<div class="row">
|
|
<div style="float: left; border: thick solid limegreen; padding-right: 10px">
|
|
@using (Html.BeginForm(controllerName: "Home", actionName: "Edit", method: FormMethod.Post))
|
|
{
|
|
<table>
|
|
<tr>
|
|
<td>
|
|
<label class="control-label col-md-2">Model.Name</label>
|
|
</td>
|
|
<td>
|
|
@Html.TextBox("Name")
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label class="control-label col-md-2">Model.Address</label>
|
|
</td>
|
|
<td>
|
|
@Html.DropDownList("Address", "Select an Address")
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label class="control-label col-md-2">Model.Age</label>
|
|
</td>
|
|
<td>
|
|
@Html.DropDownListFor(model => model.Age, (IEnumerable<SelectListItem>)ViewBag.Ages, htmlAttributes: new { @class = "form-control" })
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<input type="submit" value="Save" class="btn btn-default" style="margin-left: 10px" />
|
|
</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
}
|
|
</div>
|
|
</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>
|
|
} |