❔ For loop not implementing properly
Hi, I'm Tasha ! Any help would be appreciated :)
The problem: my fake DB isn't populating with data. It returns my error handle of "No data found" when there is clearly data.
The fake DB - pizza.cshtml.cs --> The Pizza Model
Models folder: PizzasModel.cs --> Getters and setters
Index.cshtml (The fake DB call to loop through everything)
Images are in "wwwroot/images/Pizzas"
The problem: my fake DB isn't populating with data. It returns my error handle of "No data found" when there is clearly data.
The fake DB - pizza.cshtml.cs --> The Pizza Model
using Microsoft.AspNetCore.Mvc.RazorPages;
using Assignment_2.Models;
namespace Assignment_2.Views
{
public class PizzaModel : PageModel
{
public List<PizzasModel> fakePizzaDB = new List<PizzasModel>()
{
new PizzasModel(){ImageTitle="Margerita", PizzaName="Margerita", BasePrice=10, TomatoPizzaSauce=true, Cheese=true, Pepperoni=false, Ham=false, Capsicum=false, Mushroom=false},
new PizzasModel(){ImageTitle="Pepperoni", PizzaName="Pepperoni", BasePrice=10, TomatoPizzaSauce=true, Cheese=true, Pepperoni=true},
};
public void OnGet()
{
}
}
}using Microsoft.AspNetCore.Mvc.RazorPages;
using Assignment_2.Models;
namespace Assignment_2.Views
{
public class PizzaModel : PageModel
{
public List<PizzasModel> fakePizzaDB = new List<PizzasModel>()
{
new PizzasModel(){ImageTitle="Margerita", PizzaName="Margerita", BasePrice=10, TomatoPizzaSauce=true, Cheese=true, Pepperoni=false, Ham=false, Capsicum=false, Mushroom=false},
new PizzasModel(){ImageTitle="Pepperoni", PizzaName="Pepperoni", BasePrice=10, TomatoPizzaSauce=true, Cheese=true, Pepperoni=true},
};
public void OnGet()
{
}
}
}Models folder: PizzasModel.cs --> Getters and setters
namespace Assignment_2.Models
{
public class PizzasModel
{
public string ImageTitle { get; set; }
public string PizzaName { get; set; }
public bool Cheese { get; set; }
public float FinalPrice { get; set; }
}
}namespace Assignment_2.Models
{
public class PizzasModel
{
public string ImageTitle { get; set; }
public string PizzaName { get; set; }
public bool Cheese { get; set; }
public float FinalPrice { get; set; }
}
}Index.cshtml (The fake DB call to loop through everything)
@model Assignment_2.Views.PizzaModel // Pizza.cshtml.cs
@if (Model != null && Model.fakePizzaDB != null && Model.fakePizzaDB.Count > 0)
{
@foreach (var pizza in Model.fakePizzaDB)
{
var ImagePath = "~/images/Pizzas/" + (pizza.ImageTitle + ".png");
<div class="">
<img src="@ImagePath" asp-append-version="true" />
<a asp-area="" asp-page="" asp-route-ImageTitle="@pizza.ImageTitle"
asp-route-PizzaPrice="@pizza.FinalPrice">Get this pizza! </a>
<br />
</div>
}
}
else
{
<p>No pizza data available.</p>
}@model Assignment_2.Views.PizzaModel // Pizza.cshtml.cs
@if (Model != null && Model.fakePizzaDB != null && Model.fakePizzaDB.Count > 0)
{
@foreach (var pizza in Model.fakePizzaDB)
{
var ImagePath = "~/images/Pizzas/" + (pizza.ImageTitle + ".png");
<div class="">
<img src="@ImagePath" asp-append-version="true" />
<a asp-area="" asp-page="" asp-route-ImageTitle="@pizza.ImageTitle"
asp-route-PizzaPrice="@pizza.FinalPrice">Get this pizza! </a>
<br />
</div>
}
}
else
{
<p>No pizza data available.</p>
}Images are in "wwwroot/images/Pizzas"
