title: Blazor: Pass a function that takes parameters to a component and call it from it
body: <p>I'm trying to split my Blazor Server project into components in order to make it more manageable.</p>
  <p>I want my component to have a function passed in as a parameter to it. The function takes a string parameter and it is called with different names from the component when a button is clicked.</p>
  <p>I've tried some answers I found online but they don't seem to work(Like binding events)</p>
  <h2>Code</h2>
  <p>I have a component named <code>ItemMenu.razor</code> and my index page <code>Index.razor</code>.</p>
  <p><code>ItemMenu.razor</code>:</p>
  <pre class="lang-cs prettyprint-override"><code>
  &lt;button @onclick=&quot;() =&gt; OnClickFunction.Invoke(foo)&quot;&gt;foo&lt;/button&gt;
  &lt;button @onclick=&quot;() =&gt; OnClickFunction.Invoke(ping)&quot;&gt;ping&lt;/button&gt;
  
  @code {
      [Parameter] public Action&lt;string&gt; OnClickFunction { get; set; }
  
      const string foo = &quot;bar&quot;;
      const string ping = &quot;pong&quot;;
  }
  
  </code></pre>
  <p><code>Index.razor</code>:</p>
  <pre class="lang-cs prettyprint-override"><code>@page &quot;/&quot;
  
  &lt;h1&gt;This is my index page!&lt;/h1&gt;
  
  &lt;ItemMenu OnClickFunction=&quot;ShowName&quot; /&gt; @*Error: No overload for 'ShowName' matches delegate 'Action'*@
  
  @code {
      public void ShowName(string myName)
      {
          Console.WriteLine(myName);
      }
  }
  
  
  </code></pre>
  <h2>Error</h2>
  <p>Line 3 in <code>Index.html</code> throws the error <code>No overload for 'ShowName' matches delegate 'Action'</code></p>
  <h2>Solution</h2>
  <p><s>Turns out I just needed to rename my variable to <code>OnClick</code> instead of <code>OnClickFunction</code>...</s></p>
  <p>Ok @enet pointed out the variable name wasn't the problem.
  In blazor we should use the EventCallback and not Action.</p>
  <p>Turns out the real problem in my case was Visual Studio as I found this solution earlier when looking at other answers. VS decided to show an error on this line even though it compiles and runs fine...</p>