dreanor
dreanor

Reputation: 75

Blazor - Adding two values during HTML render

This question feels kinda silly but basically:

I have two integers, one of which can change dynamically during runtime.

        <table>
             @foreach(var foo in bar)
                {
                    <tr>
                        <td>...</td>
                    </tr>
                }
        </table>

@code
{
     int v1 = 1; //May change anytime
     List<Model> bar;



public class Model
    {
        public int v2 { get; set; }
    }


}

What I need is to display the sum of v1 and v2 (for each object) when the table is rendered. Is there an easy way to do this?

Upvotes: 1

Views: 820

Answers (1)

Henk Holterman
Henk Holterman

Reputation: 273804

The display is easy

<td>The sum is @(foo.v2 + v1)</td>

one of which can change dynamically during runtime

When it changes as the result of a normal Blazor lifecycle event (ButtonClick or something) : you don't have to do anything.

When it changes by some background process you will have to call StateHasChanged() when it happens.

Upvotes: 5

Related Questions