Question: Create an action method called Purchase inside PizzasStatic controller. This method should: - Have two parameters: int PizzaType and int PizzaCount - Calculate the total
Create an action method called "Purchase" inside PizzasStatic controller. This method should:
- Have two parameters: int PizzaType and int PizzaCount
- Calculate the total price for purchasing pizzas of PizzaType with the quantity of PizzaCount.
- Use a View file to generate HTTP response, and pass the following values to this View file:
- The pizza name corresponding to the PizzaType.
- The total price to pay.
//Pizzastatic
@{ ViewData["Title"] = "Home Page"; }
| Pizza Type | Pizza Name | Price |
|---|---|---|
| 1 | BBQ Beef | $10.50 |
| 2 | Chicken and Pineapple | $8.50 |
| 3 | Pepperoni Feast | $9.00 |
| 4 | Vegetarian | $7.00 |
//Control
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc;
// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace GourmetPizza.Controllers { public class PizzasStatic : Controller { // GET: /
//GET: http://localhost:xxx/PizzasStatic/Purchase?PizzaType&PizzaCount public IActionResult Purchase(int PizzaType, int PizzaCount) {
ViewData["PizzaType"] = PizzaType; ViewData["PizzaCount"] = PizzaCount;
return View(); }
} }
//Purchase
@{ ViewData["Title"] = "Home Page"; }
@if ((int)ViewData["PizzaType"] == 1) { // (int)ViewData["PizzaCount"] * $10.50;
}
@if ((int)ViewData["PizzaType"] == 2) { // (int)ViewData["PizzaCount"] * $8.50; }
@if ((int)ViewData["PizzaType"] == 3) { // (int)ViewData["PizzaCount"] * $9.00; }
@if ((int)ViewData["PizzaType"] == 4) { // (int)ViewData["PizzaCount"] * $7.00; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
