Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Setting a property in Blazor

I’ve spent too many hours trying to accomplish something that should be very simple, so reaching out to this group. I’m simply trying to update the value of a property of a Blazor form but it doesn’t execute the code–it only renders the code on the browser page.

I’m trying to set the variable priorWorkspace to the value of rpt.WorkspaceName as @priorWorkspace = @rpt.WorkspaceName but it doesn’t work and the rpt.WorkspaceName is rendered.

Obviously, I’m new at this, so be nice. 🙂

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

    <table class="table">
    <thead>
        <tr>
            <th>Select</th>
            <th>Workspace</th>
            <th>Report Name</th>
            <th>Report Desc</th>
        </tr>
    </thead>

    <tbody>
        @foreach (var rpt in rptObj)
        {
            <tr>
                @if (@priorWorkspace == @rpt.WorkspaceName)
                {
                    <td></td>
                    <td>@rpt.WorkspaceName</td>
                    <td>@rpt.ReportName</td>
                    <td>@rpt.ReportDesc</td>
                    }
                else 
                {
                    <td><input type="checkbox" value="@rpt.WorkspaceName" checked="@isChecked" @onchange="eventArgs => { CheckboxChanged(rpt, eventArgs.Value); }"></td>
                    <td>@rpt.WorkspaceName</td>
                    <td>@rpt.ReportName</td>
                    <td>@rpt.ReportDesc</td>
                    }
            </tr>
            <code>@priorWorkspace = @rpt.WorkspaceName</code>
        }
    </tbody>
</table>


@code {

    public string priorWorkspace = "";
    List<PowerBIWorkspace> rptObj;
}

>Solution :

I think this is what you want. I didn’t test it.

@{
    string priorWorkspace = "";
    foreach (var rpt in rptObj)
        {
            <tr>
                @if (priorWorkspace == rpt.WorkspaceName)
                {
                    <td></td>
                    <td>@rpt.WorkspaceName</td>
                    <td>@rpt.ReportName</td>
                    <td>@rpt.ReportDesc</td>
                    }
                else 
                {
                    <td><input type="checkbox" value="@rpt.WorkspaceName" checked="@isChecked" @onchange="eventArgs => { CheckboxChanged(rpt, eventArgs.Value); }"></td>
                    <td>@rpt.WorkspaceName</td>
                    <td>@rpt.ReportName</td>
                    <td>@rpt.ReportDesc</td>
                    }
            </tr>

            priorWorkspace = rpt.WorkspaceName;
        }
}

@code {

    //public string priorWorkspace = "";
    List<PowerBIWorkspace> rptObj;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading