I am receiving an error of CS0103 - 'The name 'newHotel' does not exist in the current context':
I've created a class called 'Hotel', and a property called 'HotelName'.
I've created a variable called 'newHotel', which is of type Hotel.
And I have initialised the variable with a value of "Paradise Beach".
@page "/hotels"
<h3>Hotels</h3>
<p>
Hotel Name: @newHotel.HotelName // **THIS IS WHERE THE ERROR IS SHOWN IN VS2019**
</p>
Remaining code:
@code {
protected override void OnInitialized()
{
base.OnInitialized();
Hotel newHotel = new Hotel
{
HotelName = "Paradise Beach"
};
}
class Hotel
{
public string HotelName { get; set; }
}
}
I can't tell where I am going wrong?
Many thanks,