简体   繁体   中英

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. :-)

    <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;
}

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM