We can assign and re-use the TValue with help of typeparam in the Blazor platform. But, how will we assign the TValue dynamically for Blazor InputNumber component?
code example:
[index.razor]
<EditForm> @*The below definiton is working*@<InputNumber TValue="int?" @bind-Value="@DynamicModelInstance.ValueAsT"></InputNumber> @*The below definiton is not working*@<InputNumber TValue="DynamicModelInstance.Type" @bind-Value="@DynamicModelInstance.ValueAsT"></InputNumber></EditForm>@code { public DynamicModel<int> DynamicModelInstance { get; set; } protected override void OnInitialized() { DynamicModelInstance = new DynamicModel<int>(); DynamicModelInstance.ValueAsT = 500; }}[DynamicModel.cs]
namespace CustomComponent.Pages{public class DynamicModel<T> where T : struct{ public System.Type Type { get; set; } public bool Enabled { get; set; } public DynamicModel() { this.Type = typeof(T); } private T _value; public T ValueAsT { get { return (T)_value; } set { this._value = value; } }}}How to achieve this requirement?