@using MvcSample.Web.Models @using Microsoft.AspNet.Mvc.ModelBinding @model User @{ ViewBag.Title = (Model == null && ViewData.ModelState.Count == 0) ? "Create Page" : "Edit Page"; if (ViewBag.Gift == null) { ViewBag.Gift = "nothing"; } }

@ViewBag.Title

Thanks for @ViewBag.Gift

@if (Model == null) {

Howdy, your model is null.

} else {

Hello @Html.DisplayTextFor(model => model.Name)! Happy @(Model.Age)th birthday.

} @{ var metadata = ViewData.ModelMetadata; if (metadata != null) { var typeName = metadata.ModelType.Name; var description = metadata.Description ?? "no description";

@typeName has description '@description' and contains

} }
@using (Html.BeginForm(controllerName: "Home", actionName: "Edit", method: FormMethod.Post)) {
@Html.TextBox("Name") @Html.ValidationMessage("Name.Name", "Name is required", new { @style = "font-weight: bold" })
@Html.DropDownList("Address", "Select an Address")
@Html.DropDownListFor(model => model.Age, (IEnumerable)ViewBag.Ages, htmlAttributes: new { @class = "form-control" }) @Html.ValidationMessageFor(model => model.Age, "Age must be between 27 and 70", new { @style = "font-weight: bold" })
@Html.TextArea("About", "You can explain about your hobbies, work etc.", 5, 40, htmlAttributes: new { style = "font-weight:bold" })
@Html.Editor("OwnedAddresses")
@Html.ListBoxFor(model => model.ParentsAges, (IEnumerable)ViewBag.Ages, htmlAttributes: new { @class = "form-control" })
}