Professional Documents
Culture Documents
Lesson12 - Exercises (PS11-12 Hoh Jungi)
Lesson12 - Exercises (PS11-12 Hoh Jungi)
Lesson12Ex1
Filename: .\Pages\Index.cshtml
@page
@model IndexModel
@{
ViewData["Title"] = "Home page";
}
<div class="text-center">
<h1 class="display-4">Welcome Jungi</h1>
<p><a href="Calculator">Jungi's Calculator</a></p>
<p><a href="BookOrder">Jungi's Book Order</a></p>
</div>
After filling in the text boxes and clicking on the "Calculate Total Price" button
After filling in the text boxes and clicking on the "Confirm" button
Filename: .\Pages\BookOrder.cshtml
@page
@model RazorPagesBasics.Pages.BookOrderModel
@{
}
<h1>Book Order (Hoh Jungi 10243292F)</h1>
<form method="post">
<p>
Title: <input type="text" asp-for="Title" />
Author: <input type="text" asp-for="Author" />
</p>
<p>
Quantity: <input type="text" asp-for="Quantity" />
Price: $<input type="text" asp-for="Price" />
</p>
<p>
<input type="submit" value="Calculate Total Price" />
<input type="submit" asp-page-handler="Confirm" value="Confirm" />
</p>
<p>@Model.Answer</p>
</form>
Filename: .\Pages\BookOrder.cshtml.cs
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace RazorPagesBasics.Pages
{
public class BookOrderModel : PageModel
{
[BindProperty]
public string Title { get; set; }
[BindProperty]
public string Author { get; set; }
[BindProperty]
public int Quantity { get; set; }
[BindProperty]
public float Price { get; set; }
public string Answer { get; set; }
public void OnPost()
{
float TotalCost = Quantity * Price;
Answer = "Total cost = $" + TotalCost.ToString();
}
public void OnPostConfirm()
{
float TotalCost = Quantity * Price;
Answer = "Order confirmed: " + Quantity + " copies of " + Title + " by " + Author + ". Total cost = $" +
TotalCost.ToString();
}
}
}