如何在ASP.NET Razor页面中使用锚定标签作为提交按钮
我在Razor页面中有一个处理程序方法,名称 ongetExpense(usePayload有效载荷)
page.cshtml:
<input type="hidden" asp-for="Filters.From" value="@Model.Filters.From.ToYYYYMMDD()" />
<input type="hidden" asp-for="Filters.To" value="@Model.Filters.To.ToYYYYMMDD()" />
<a asp-page-handler="Expense" class="btn btn-primary" type="button" style="border-color: inherit">
Expense
</a>
page.cshtml.cs:
public IActionResult OnGetExpense(UserPayload filter)
{
Console.WriteLine(filter.From);
Console.WriteLine(filter.To);
return Page();
}
来自日期,我所得到的是<代码> 01-01-0001 它没有提交我需要的有效载荷。
有没有标签属性,我可以带有锚标签的有效载荷?
请帮忙
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的渲染标签将创建到端点的GET请求,您需要到帖子以发送请求正文中的数据,并使控制器将请求主体绑定到您的用户Payload对象。
要发送邮政请求,您可以写一些JavaScript并将其发布到JSON到终点,也可以以形式包装代码。
您的控制器需要具有
httppost
分配的属性。Your rendered A tag will create a GET request to the endpoint, you need to to a POST to send the data in the body of the request and for the Controller to bind the Request Body to your UserPayload object.
To send the POST request you can either write some JavaScript and POST to JSON to the end point or wrap the code in a Form.
https://learn.microsoft.com/en-us/aspnet/web-pages/overview/ui-layouts-and-themes/4-working-with-forms
Your controller will need to have
HttpPost
attribute assigned.您可以在下面使用
ASP-Route- {value}
是一个工作演示,您可以参考它。
cshtml:
cshtml.cs
结果:
You can use
asp-route-{value}
Below is a work demo, you can refer to it.
cshtml:
cshtml.cs
result: