1
0
mirror of https://github.com/rudollee/LearningMVC.git synced 2026-08-11 16:32:55 +00:00

Ch. 21 Helper Methods

This commit is contained in:
wook
2017-04-18 00:50:18 +09:00
parent a3ef7da060
commit 1eb39e5afc
32 changed files with 23656 additions and 0 deletions
@@ -0,0 +1,39 @@
@model HelperMethods.Models.Person
@{
ViewBag.Title = "CreatePerson";
Layout = "/Views/Shared/_Layout.cshtml";
}
<h2>CreatePerson</h2>
@*@{ Html.BeginForm();}*@
@using (Html.BeginRouteForm("FormRoute", new { }, FormMethod.Post,
new { @class = "personClass", data_formtype = "person" }))
{
<div class="dateElem">
<label>PersonId</label>
@*<input name="personId" value="@Model.PersonId" />*@
@*@Html.TextBox("personId", @Model.PersonId)*@
@Html.TextBoxFor(m => m.PersonId)
</div>
<div class="dateElem">
<label>First Name</label>
@*<input name="FirstName" value="@Model.FirstName" />*@
@*@Html.TextBox("FirstName", @Model.FirstName)*@
@Html.TextBoxFor(m => m.FirstName)
</div>
<div class="dateElem">
<label>Last Name</label>
@*<input name="LastName" value="@Model.LastName" />*@
@*@Html.TextBox("LastName", @Model.LastName)*@
@Html.TextBoxFor(m => m.LastName)
</div>
<div class="dateElem">
<label>Role</label>
@Html.DropDownListFor(m => m.Role, new SelectList(Enum.GetNames(typeof(HelperMethods.Models.Role))))
</div>
<input type="submit" value="Submit" />
}
+49
View File
@@ -0,0 +1,49 @@
@model string
@using HelperMethods.Infrastructure
@{
Layout = null;
}
@*@helper ListArrayItems(string[] items)
{
<ul>
@foreach (string str in items)
{
<li>@str</li>
}
</ul>
}*@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<div>
Here are the fruits: @Html.ListArrayItems((string[])ViewBag.Fruits) @*@ListArrayItems(ViewBag.Fruits)*@
@*@foreach (string str in (string[])ViewBag.Fruits)
{
<b>@str</b>
}*@
</div>
<div>
Here are the cities: @Html.ListArrayItems((string[])ViewBag.Cities) @*@ListArrayItems(ViewBag.Cities)*@
@*@foreach (string str in (string[])ViewBag.Cities)
{
<b>@str</b>
}*@
</div>
<div style="border: thin solid black; padding: 10px;">
Here is the message:
<p>@Model</p>
</div>
<p>This is the content from the helper method:</p>
<div style="border: thin solid black; padding: 10px;">
@Html.DisplayMessage(Model)
</div>
</body>
</html>