I have a simple Razor page and I'm trying to display a button which when clicked will execute a method in the page model code behind, similar to C#'s WPF button. I don't want to use any javascript at all.
I've gotten to a point where it kinda does what I want it to but on page load it executes the method for each element in the for each list. This is something I don't want, I just want the method to be executed on button press.
The razor page code with the for loop is as follows:
@foreach (var item in @Model.UserData)
{
<tr>
<td>@item.Owner</td>
<td>@item.InputPath</td>
<td>@item.OutputPath</td>
<td>@item.Status</td>
<td>
<form asp-action="@Model.DownloadCsv(@item.OutputPath)" method="post">
<button>Download</button>
</form>
</td>
</tr>
<tr>
<td colspan="5"> <hr /> </td>
</tr>
}
In the code behind I just have this right now:
public IActionResult DownloadCsv(string inputPath)
{
int i = 0;
return Page();
}