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>
+15
View File
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title</title>
<style type="text/css">
label {display: inline-block; width: 100px;}
div.dateElem {margin: 5px;}
</style>
</head>
<body>
@RenderBody()
</body>
</html>
+3
View File
@@ -0,0 +1,3 @@
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
+42
View File
@@ -0,0 +1,42 @@
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="HelperMethods" />
</namespaces>
</pages>
</system.web.webPages.razor>
<appSettings>
<add key="webpages:Enabled" value="false" />
</appSettings>
<system.webServer>
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
<system.web>
<compilation>
<assemblies>
<add assembly="System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
</system.web>
</configuration>