so im building some wraper around select list
lets consider basic example DictListComponent.razor
@using System.Linq.Expressions
@typeparam T
<MudSelect T="T" @bind-Value="Value" For="@For" AnchorOrigin="Origin.BottomCenter">
<MudSelectItem T="int?" Value="null"> </MudSelectItem>
<MudSelectItem T="int?" Value="1">1</MudSelectItem>
<MudSelectItem T="int?" Value="2">2</MudSelectItem>
</MudSelect>
usage would be
<DictMudSelectComponent @bind-Value="@model.dict1" For="@(() => @model.dict1)" ></DictMudSelectComponent>
this is fine
then if i want to change to pass this AnchorOrigin from parrent like
usage would be:
<DictMudSelectComponent @bind-Value="@model.dict1" For="@(() => @model.dict1)" AnchorOrigin="Origin.BottomCenter"></DictMudSelectComponent>
then in DictListComponent.razor i add
<MudSelect T="T" @bind-Value="Value" For="@For" @attributes=AllOtherAttributes>
<MudSelectItem T="int?" Value="null"> </MudSelectItem>
<MudSelectItem T="int?" Value="1">1</MudSelectItem>
<MudSelectItem T="int?" Value="2">2</MudSelectItem>
</MudSelect>
@code
{
[Parameter(CaptureUnmatchedValues = true)]
public Dictionary<string, object> AllOtherAttributes { get; set; } = new();
}
then in runtime i get
Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Unable to set property 'AnchorOrigin' on object of type 'MudBlazor.MudSelect`1[[System.Int32, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]'. The error was: Specified cast is not valid.
System.InvalidOperationException: Unable to set property 'AnchorOrigin' on object of type 'MudBlazor.MudSelect`1[[System.Int32, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]'. The error was: Specified cast is not valid.
---> System.InvalidCastException: Specified cast is not valid.
at Microsoft.AspNetCore.Components.Reflection.PropertySetter.CallPropertySetter[MudSelect`1,Origin](Action`2 setter, Object target, Object value)
at Microsoft.AspNetCore.Components.Reflection.PropertySetter.SetValue(Object target, Object value)
at Microsoft.AspNetCore.Components.Reflection.ComponentProperties.<SetProperties>g__SetProperty|3_0(Object target, PropertySetter writer, String parameterName, Object value)
--- End of inner exception stack trace ---
at Microsoft.AspNetCore.Components.Reflection.ComponentProperties.<SetProperties>g__SetProperty|3_0(Object target, PropertySetter writer, String parameterName, Object value)
at Microsoft.AspNetCore.Components.Reflection.ComponentProperties.SetProperties(ParameterView& parameters, Object target)
at Microsoft.AspNetCore.Components.ParameterView.SetParameterProperties(Object target)
at Microsoft.AspNetCore.Components.ComponentBase.SetParametersAsync(ParameterView parameters)
at MudBlazor.MudBaseInput`1[[System.Int32, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].<>n__1(ParameterView parameters)
at MudBlazor.MudBaseInput`1.<SetParametersAsync>d__177[[System.Int32, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
why this does not work ? what am i missing here? thanks andd regards !
CodePudding user response:
Try: AnchorOrigin="@(Origin.BottomCenter)"
because I think that without the @
it is just passed as a string.