Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

How to dynamically set TValue property of InputNumber component

$
0
0

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?


Viewing all articles
Browse latest Browse all 4839

Trending Articles