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

Convert a value to int from string in @bind-Value in Blazor

$
0
0

In my Blazor page, I have this simple code (ToggleButtonGroup is from here).

<div class="col-lg-6"><label class="form-label form-field-label">Insert your value</label><ToggleButtonGroup Options="@GroupOptions.Options0To10"         @bind-Value="@_session.InteractiveNumber" /><hr></div>

The model I use is defined like that

public class Session {    public int ActiveNumber { get; set; }}public Session _session = new();

The ToggleButtonGroup returns a string as a value but I want to store in the database and this is why the Session is defined like that. How can I cast the value from a string to int? Can I use something like @(e => _session.ActiveNumber = e.ToString())?


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>