てぃぐれのプログラマwiki

ワクワクに従う

it does not have [ParameterAttribute] or [CascadingParameterAttribute] applied. 【C#/Blazor】

エラーメッセージ

 Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: Object of type
'BlazorApplicationxxx.Pages.Components.BmiChild'
has a property matching the name 'xxxx', but it does not have
[ParameterAttribute] or [CascadingParameterAttribute] applied.

 

問題のコード

コンポーネント

  public double Weight
    {
        get => _Weight;
        set
        {
            _Weight = value;
            this.result = Weight / *1;
        }
    }

 

親から子(Weight)を呼び出し

<BlazorApplication2.Pages.Components.BmiChild @bind-Weight="Weight" />

 

解決

 [Parameter]
   public double Weight
    {
        get => _Weight;
        set
        {
            _Weight = value;
            this.result = Weight / *2;
        }
    }

 

エラー通りにパラメータ属性を追加してあげて解決。

外部からプロパティにアクセスする場合は、プロパティにパラメータ属性を追加してあげる。

*1:Height / 100) * (Height / 100

*2:Height / 100) * (Height / 100