dzed-baradzed
6/19/2017 - 2:53 PM

ASP.NET MVC Basics Treehouse Course

ASP.NET MVC Basics Treehouse Course

// ComicBooksControllers.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace ComicBookGallery.Controllers
{
  public class ComicBooksController : Controller
  {
    public ActionResult Detail()
    {
      ViewBag.SeriesTitle = "The Amazing Spider-Man";
      ViewBag.IssueNumber = 700;
      ViewBag.Description = "<p>Final issue! Witness the final hours of Doctor Octopus' life and his one, last, great act of revenge! Even if Spider-Man survives... <strong>will Peter Parker?</strong></p>";
      ViewBag.Artists = new string[]
      {
        "Script: Dan Slott",
        "Pencils: Humberto Ramos",
        "Inks: Victor Olazaba",
        "Colors: Edgar Delgado",
        "Letters: Chris Eliopoulos"
      };

      return View();
    }  
  }
}


// --------------------------------------------------------------------------


// Detail.cshtml

@{
  Layout = "~/Views/Shared/_Layout.cshtml";
  ViewBag.Title = "Comic Book Detail";
}


<div>
  <h1>@ViewBag.SeriesTitle</h1>
  <h2>Issue #@ViewBag.IssueNumber</h2>

  <h5>Description</h5>
  <p>@Html.Raw(@ViewBag.Description)</p>

  @if (ViewBag.Artists.Length > 0)
  {
    <h5>Artists:</h5>
    <ul>
      @foreach (var artist in ViewBag.Artists)
      {
        <li>@artist</li>
      }
    </ul>
  }
</div>



// -------------------------------------------------------------------


//_Layout.cshtml

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title - Comic Book Gallery</title>
    <link href="~/Content/site.css" rel="stylesheet" type="text/css" />
    <link href="~/Content/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <script src="~/Scripts/modernizr-2.6.2.js"></script>
</head>
<body>
    <div class="navbar navbar-inverse navbar-fixed-top">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                @Html.ActionLink("Comic Book Gallery", "Index", "ComicBooks", new { area = "" }, new { @class = "navbar-brand" })
            </div>
            <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                    <!-- Add menu items here -->
                </ul>
            </div>
        </div>
    </div>

    <div class="container body-content">
        @RenderBody()
        <hr />
        <footer>
            <p>&copy; @DateTime.Now.Year - Comic Book Gallery</p>
        </footer>
    </div>

    <script src="~/Scripts/jquery-1.10.2.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
</body>
</html>


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace ComicBookGallery.Controllers
{
  public class ComicBooksController : Controller
  {
    public ActionResult Detail()
    {
      if (DateTime.Today.DayOfWeek == DayOfWeek.Monday)
      {
        return Redirect("/");
      }
      return Content("Hello World!");
    }  
  }
}