Search code examples
c#parametersonclickblazorfluent-ui

Blazor set parameter on FluentButton onClick event


I am trying to set the R_Id parameter on the FluentButton Navigate method, but the reference does not exist in current context. I am new to C# and have spent hours on this to no avail.

The data populates the grid fine, its just getting that paramater set on the onClick event that is the problem.

I did try to adjust the Items to AsEnumerable, that fixed the error on the click but created a new CS0411 error on the DataGrid.

     <FluentDataGrid Items="@sccRequests" Pagination="@pagination">
  <PropertyColumn Property="@(p => p.R_id)" Sortable="true" />
  <PropertyColumn Property="@(p => p.frmwhen)" Format="yyyy-MM-dd" Sortable="true" />
  <PropertyColumn Property="@(p => p.SKU)" Sortable="true" />
  <PropertyColumn Property="@(p => p.related)"  Sortable="true" />
  <PropertyColumn Property="@(p => p.status)" Sortable="true" />
  <TemplateColumn Title="Actions" Align="@Align.End">
           <FluentButton IconEnd="@(new Icons.Regular.Size16.Edit())" @onclick="@(e => Navigate(R_id))" />
      </TemplateColumn>
  

code:

    public IQueryable<RequestModel>? sccRequests { get; set; }


public async Task RefreshReadData()
{
   sccName = userModel?.userEmail;
   sccRequests = null;
   sccRequests = (await sql.GetRequestsByScc(sccName)).AsQueryable();
    
}


Solution

  • The template column is a "templated component".

    Inside you can access the item with context. .

    <FluentButton @onclick="() => Navigate(context.R_Id)" ... />