MicrosoftDocs / mslearn-interact-with-data-blazor-web-apps

Sample repo for Interact with Data for Blazor Web Apps Learn Module
Creative Commons Attribution 4.0 International
44 stars 209 forks source link

Exercise — Share data in Blazor applications #14

Closed Menelion closed 1 year ago

Menelion commented 1 year ago

In Exercise — Share data in Blazor Applications there is a ConfigurePizzaDialog.razor file where there is this line and lines below:

            <h2>@Pizza.Special.Name</h2>
            @Pizza.Special.Description

VS Code complains:

An object reference is required for the non-static field, method, or property 'Pizza.Special' [BlazingPizza]

If however I set it to static, I get complains for index.razor:

      configuringPizza = new Pizza()
      {
          Special = special,
          SpecialId = special.Id,
          Size = Pizza.DefaultSize
      };

It says (obviously) it cannot set a static property on a class instance.

What is the solution to this problem? Thanks.

Menelion commented 1 year ago

Mea culpa. I missed the @code{} directive on the next step:

@code {
    [Parameter] public Pizza Pizza { get; set; }
}