PRACTICAL 3: WORKING WITH RAZOR VIEWS

STEPS:
1. Create a new project, same as the MVC project (ASP.NET Core Web Application > MVC).
2. For creating the view page: Views > Home > Add > View > Price.cshtml.
3. In Controllers > HomeController, add the IActionResult "Price" to the code.
4. In Index.cshtml, add a link for Price.cshtml.
5. Run the project and click the link.

A. IF / ELSE IN RAZOR VIEW

CODE: (Views/Home/Price.cshtml)
@{
    var price = 60;
}
<html>
<body>
    @if (price > 50)
    {
        <p>The price is greater than 50.</p>
    }
    else
    {
        <p>Price is less than 50.</p>
    }
</body>
</html>

CODE: (Controllers/HomeController.cs - add this action)
public IActionResult Price()
{
    return View();
}

CODE: (Views/Home/Index.cshtml)
@{
    ViewData["Title"] = "Home Page";
}

<div class="text-center">
    <h1 class="display-4">Welcome</h1>
    <p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
    <p><a href="Home/Price"> Razor Example </a></p>
</div>

OUTPUT:
Click "Razor Example" -> the page shows: The price is greater than 50.


B. SWITCH CASE IN RAZOR VIEW

STEPS:
1. In HomeController.cs add the action Month.
2. In Views > Home add the view Month.cshtml.
3. In Index.cshtml add a link for Home/Month.

CODE: (Controllers/HomeController.cs - add this action)
public IActionResult Month()
{
    return View();
}

CODE: (Views/Home/Month.cshtml)
@{
    ViewData["Title"] = "Month";
}

@{
    var month = DateTime.Now.ToString("MMMM");
    var message = "";
}

<html>
<body>
    @{
        switch (month)
        {
            case "January":
                message = "Starting of the Year";
                break;
            case "July":
                message = "Middle of the Year";
                break;
            case "December":
                message = "Ending of the Year";
                break;
            default:
                message = "Any Month in between";
                break;
        }
    }
    <p>@message</p>
</body>
</html>

CODE: (Views/Home/Index.cshtml)
@{
    ViewData["Title"] = "Home Page";
}

<div class="text-center">
    <h1 class="display-4">Welcome</h1>
    <p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
    <p><a href="Home/Month">CLick</a></p>
</div>

OUTPUT:
Click "CLick" -> the page shows the message for the current month
(January / July / December / "Any Month in between").
