title: How do I have multiple GET buttons with multiple handlers on a ASP.NET Core razor page?
body: <p>I have a Razor file with search and download functionality.</p>
  <ol>
  <li>The user can enter text, click search and the list of files is filtered.</li>
  <li>The user can also click a download button next to each file.</li>
  </ol>
  <p>The search functionality works.</p>
  <p>When the user clicks download, the OnGet handler is called instead of OnGetDownload.</p>
  <p>Here is the cshtml.</p>
  <pre><code>@page
  @model IndexModel
  @{
      ViewData[&quot;Title&quot;] = &quot;Home page&quot;;
  }
  
  &lt;form&gt;
      Search
      &lt;input type=&quot;text&quot; asp-for=&quot;FilenameFilter&quot; class=&quot;form-control&quot; placeholder=&quot;Filename ...&quot; autocomplete=&quot;off&quot; /&gt;
      &lt;button type=&quot;submit&quot;&gt;Search&lt;/button&gt;
  &lt;/form&gt;
  
  &lt;form&gt;
      Download
      &lt;table&gt;
          &lt;thead&gt;
              &lt;tr&gt;
  
                  &lt;th&gt;File Name&lt;/th&gt;
  
              &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tbody&gt;
              @foreach (var file in Model.Files)
              {
                  &lt;tr&gt;
                      &lt;td&gt;@file&lt;/td&gt;
                      &lt;td&gt;&lt;button type=&quot;submit&quot; asp-page-handler=&quot;Download&quot; asp-route-name=@file&gt;Download&lt;/button&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
              }
          &lt;/tbody&gt;
      &lt;/table&gt;
  &lt;/form&gt;
  </code></pre>
  <p>Here the C# code.</p>
  <pre><code>public class IndexModel : PageModel
  {
      private readonly ILogger&lt;IndexModel&gt; _logger;
  
      [BindProperty(SupportsGet = true)]
      public string FilenameFilter { get; set; }
  
      public IEnumerable&lt;string&gt; Files { get; set; }
  
      public IndexModel(ILogger&lt;IndexModel&gt; logger)
      {
          _logger = logger;
  
          Files = new List&lt;string&gt; { &quot;file1.txt&quot;, &quot;file2.txt&quot;, &quot;file3.txt&quot; };
      }
  
      public void OnGet()
      {
          //This gets called for all button events (search  and download)
          _logger.LogInformation($&quot;OnGet {FilenameFilter}&quot;);
  
      }
  
      public void OnGetDownload(string name)
      {
          //This is not being called &lt;---------------------------------
          _logger.LogInformation($&quot;OnGetDownload {name}&quot;);
      }
  }
  </code></pre>
  <p>In the browser developer tools I can see that the route seems to be correct i.e.</p>
  <pre><code>&lt;button type=&quot;submit&quot; formaction=&quot;/?name=file3.txt&amp;amp;handler=Download&quot;&gt;
  </code></pre>
  <hr />
  <p><strong>Update</strong></p>
  <p>If I change the second form to <code>&lt;form method=&quot;post&quot;&gt;</code> and the handler to Post then the download handler is called. But semantically this is not a post method. How do I have 2 get handlers?</p>
  <hr />
  <p><strong>Update</strong></p>
  <p>Here is the update to the cshtml file (for the comment from Chetan Ranpariya). The problem persists.</p>
  <pre><code>@page
  @model IndexModel
  @{
      ViewData[&quot;Title&quot;] = &quot;Home page&quot;;
  }
  
  &lt;form&gt;
      Search
      &lt;input type=&quot;text&quot; asp-for=&quot;FilenameFilter&quot; class=&quot;form-control&quot; placeholder=&quot;Filename ...&quot; autocomplete=&quot;off&quot; /&gt;
      &lt;button type=&quot;submit&quot;&gt;Search&lt;/button&gt;
  &lt;/form&gt;
  
  Download
  &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
  
              &lt;th&gt;File Name&lt;/th&gt;
  
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          @foreach (var file in Model.Files)
          {
              &lt;tr&gt;
                  &lt;td&gt;@file&lt;/td&gt;
                  &lt;td&gt;
                      &lt;form method=&quot;get&quot; action=&quot;OnGetDownload&quot;&gt;
                          &lt;button type=&quot;submit&quot; asp-page-handler=&quot;Download&quot; asp-route-name=@file&gt;Download
                          &lt;/button&gt;
                      &lt;/form&gt;
  
                  &lt;/td&gt;
              &lt;/tr&gt;
          }
      &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>