0

So I'm trying to make a Blazor application that displays a customers data. When all the customers are displayed I would like to be able to navigate to an individual customer. I am having trouble making this work. The main concept is in the code below as well I have the expected model.

           @for(int i = 0; i < customers.Length-1; i++)
            {
            
                <tr>
                    <td>@customer.Id</td>
                    <td>@customer.CustomerId</td>
                    <td>@customer.LastName</td>
                    <td>@customer.FirstName</td>
                    <td>@customer.Name1056Form</td>
                    <td>@customer.TrapezeClientId</td>
                    <td>@customer.CustomerNote</td>
                    <td @onclick="NavToCustomer(i)"> Details</td>
                </tr>



      private void NavToCustomer(int i)
      {
       int Id = i;
        navigation.NavigateTo("/Customer/" + Id);

       }
          }
Brsn00
  • 37
  • 3
  • 1
    `I am having trouble making this work.` - Can you elaborate? What's not working? – devNull Jun 29 '21 at 01:36
  • Hello, I'm getting a "cannot convert from 'void' to 'Microsfot.AspNetCore.Components.EventCallBack'" error. – Brsn00 Jun 29 '21 at 01:40
  • Does this answer your question? [C# Blazor WebAssembly: Argument 2: cannot convert from 'void' to 'Microsoft.AspNetCore.Components.EventCallback'](https://stackoverflow.com/questions/64962821/c-sharp-blazor-webassembly-argument-2-cannot-convert-from-void-to-microsoft) – devNull Jun 29 '21 at 01:43

1 Answers1

0
<td @onclick="()=>NavToCustomer(@customer.Id)"> Details</td>


private void NavToCustomer(int custID)
{
    navigation.NavigateTo("/Customer/" + custID);
}

Explanation: the vanilla @onclick sends its own arguments (you can see what they are by hovering over "@onclick" in your markup). Your event handler doesn't handle MouseEventArgs, so the signatures don't match. You want to send custom info, so you should use the lambda expression instead.

--edit--

On second thought, can you just directly do this?

<td @onclick="()=>navigation.NavigateTo("/Customer/" + customer.Id)"> Details</td>
Bennyboy1973
  • 3,413
  • 2
  • 11
  • 16