Invoke custom methods

This article needs an update badly. The Invoke custom method action doesn't exist in Blazor apps. Neither does ServerMethodsController.cs. The reason is simple - Blazor doesn't need all that. In Blazor apps Radzen has the Invoke method action.

You can add a method to the code-behind of your page - that is the XXX.razor.cs file (use Visual Studio or other text editor to do that). Radzen should guess the type of the method and display it so you can invoke it.

And here is the page code-behind class with the method definitions:

  public partial class PageComponent
  {
    [Inject]
    public HttpClient HttpClient { get; set; }

    public async Task<IEnumerable<GitHubIssue>> GetIssues(string repo)
    {
      var message = new HttpRequestMessage(HttpMethod.Get, $"https://api.github.com/repos/{repo}/issues?state=open&sort=created&direction=desc");
      message.Headers.Add("Accept", "application/vnd.github.v3+json");
      message.Headers.Add("User-Agent", "HttpClient");

      var response = await HttpClient.SendAsync(message);

      response.EnsureSuccessStatusCode();

      var json = await response.Content.ReadAsStringAsync();

      return JsonSerializer.Deserialize<IEnumerable<GitHubIssue>>(json, new JsonSerializerOptions
      {
        PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
        PropertyNameCaseInsensitive = true,
      });
    }

    public int Sum(int x, int y)
    {
        return x + y;
    }
  }