title: Passing method to component
body: <p>I have been trying to work out how if its possible and how to pass a method from the main page into a component in Blazor.</p>
  
  <p>I have a simple razor page, which contains a component with a button.  I want to pass the onclick method from the razor page to the button in the component</p>
  
  <p>Note: I do not need this method to return anything void is fine.  I just need to be able to call a method from the main page in a button on the component.  I only added int here as a guess since it was complaining about T</p>
  
  <h1>Page</h1>
  
  <pre><code>@page "/test"
  @using Testing.Client.Model;
  @using System.Threading;
  
  &lt;TestMethodPassing ExternalMethod="@btnClick"&gt;&lt;/TestMethodPassing&gt;
  
  @code {
  
      public Action&lt;int&gt; btnClick(){ return 1;}
  
  }
  </code></pre>
  
  <h1>Model for component</h1>
  
  <pre><code>public class TestingMethodPassingModel : ComponentBase
  {
      [Parameter]
      protected Action&lt;int&gt; ExternalMethod { get; set; }
  }
  </code></pre>
  
  <h1>component</h1>
  
  <pre><code>@inherits TestingMethodPassingModel;
  @using testing.Client.Model;
  @using System.Threading;
  
  
  &lt;button class="btn btn-primary" @onclick="@ExternalMethod" autofocus&gt;External button&lt;/button&gt;
  
  
  @code {
  
  
      }
  </code></pre>
  
  <h1>Errors</h1>
  
  <p>The above code gives me the following error</p>
  
  <blockquote>
    <p>Gives me No overload for 'btnClick' matches delegate 'Action'</p>
  </blockquote>
  
  <p>I tried doing type T as well and that failed as Blazor cant for some reason find the reference for type T</p>
  
  <h1>Update Note</h1>
  
  <p>Working example pieced together from the answers.   <a href="https://github.com/LindaLawton/BlazorExamples/tree/master/src/PassingMethodToComponent" rel="noreferrer">PassingMethodToComponent</a></p>