'how to submit inputs to a handler methods in razor pages?
I am using razor pages I have 2 inputs dates:
<input type="hidden" asp-for="Filters.From" value="@Model.Filters.From.ToString("yyyy-MM-dd")" />
<input type="hidden" asp-for="Filters.To" value="@Model.Filters.To.ToString("yyyy-MM-dd")" />
<a asp-page-handler="Export" class="btn btn-primary" type="button" style="border-color: inherit">
Export
</a>
I want to submit the inputs to a GET method named OnGetExport
public IActionResult OnGetExport(CustomersPayload filter)
{
return Page();
}
payload:
public class CustomersPayload
{
public DateTime From { get; set; }
public DateTime To { get; set; } }
}
How can I can I call this OnGetExport method with those 2 input payload with using anchor tag?
Solution 1:[1]
Try to use asp-route-xxx to pass data to OnGetExport with anchor tag:
<a asp-page-handler="Export" class="btn btn-primary" type="button" style="border-color: inherit" asp-route-From="@Model.Filters.From.ToString("yyyy-MM-dd")" asp-route-To="@Model.Filters.To.ToString("yyyy-MM-dd")">
Export
</a>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Yiyi You |

