我使用Razor和ASP构建和Web应用程序。网络MVC 所以我有一个表格和两个按钮接受和拒绝 问题是,如果我单击“接受”,并且在页面加载过程中,我单击按钮拒绝,那么我的程序将执行“拒绝”过程
如何处理?我只想处理单击的第一个按钮
这是我的一些代码
<table class="float-right">
<tr>
<td>
<form asp-page-handler="Accept"
asp-route-id="@Model.RequestDetail.EmployeeLeaveHistoryId">
<button class="btn btn-primary">Accept</button>
</form>
</td>
<td>
<button type="button" data-toggle="modal" data-target="#myModal" class="btn btn-warning">Decline</button><br />
</td>
<td>
<a asp-page="/Leave/Request/Inbox"
asp-route-search="@Model.Keywords"
asp-route-p="@Model.PreviousPage"
class="btn btn-danger">Back</a>
</td>
</tr>
<tr>
<td><br /></td>
</tr>
</table>
</div>
和控制器
public async Task<IActionResult> OnPostAccept(Guid id)
{
var approverId = User.Claims
.Where(Q => Q.Type == ClaimTypes.PrimarySid)
.Select(Q => Q.Value)
.FirstOrDefault();
await leaveService.AcceptRequest(id, approverId);
return RedirectToPage("/Leave/Request/Inbox");
}
public async Task<IActionResult> OnPostDecline(Guid id, string declineReason)
{
var approverId = User.Claims
.Where(Q => Q.Type == ClaimTypes.PrimarySid)
.Select(Q => Q.Value)
.FirstOrDefault();
await leaveService.DeclineRequest(id, approverId, declineReason);
return RedirectToPage("/Leave/Request/Inbox");
}