【发布时间】:2021-01-04 22:23:00
【问题描述】:
我想将删除按钮从 ajax 按钮更改为 html 按钮。我目前正在使用 ajax/javascript 作为删除按钮。当我点击删除按钮时,会出现一个确认我要删除的模式窗口,一旦我点击确认,它将删除投票。删除操作重定向我更改为 RedirectToAction 但页面错误(InvalidOperationException:没有路由与提供的值匹配。)。我认为重定向不正确,或者我可能需要为该方法再次返回?
<div class="modal fade" id="delete-vote-modal" tabindex="-1"
role="dialog"
data-backdrop="static">
<form method="post" asp-controller="Discussion" asp-action="DeleteVote"
enctype="multipart/form-data">
<input id="packet-item-id" asp-for="@Model.PacketItemId" type="hidden"
/>
<input id="voting-type" asp-for="@Model.VotingType" type="hidden"
/>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Delete Vote</h5>
<button type="button" class="close" data-dismiss="modal"
aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<input type="hidden" name="voteId" id="voteId" value="" />
Do you want to delete this vote ?
<div style="text-align: center; display: none"
id="loaderDiv">
<img src="~/images/loading.gif" width="150" />
</div>
</div>
<div class="modal-footer">
<a href="#" class="btn btn-default" data-
dismiss="modal">Cancel</a>
<input type="submit"
value="Confirm"
class="btn btn-success col-sm-12 col-md-2 col-lg-2"
data-action="submit" />
</div>
</div>
</div>
</form>
[HttpPost]
public async Task<IActionResult> DeleteVote(long voteId, int
packetItemId, string votingType, CancellationToken cancellationToken)
{
try
{
await _discussionService.DeleteVoteAsync(
voteId,
cancellationToken)
.ConfigureAwait(true);
TempData.Put(key: TempDataKey.Vote.DeleteMessage,
StatusMessageModel.Create(UserStringsService.VoteDeletedSuccessfully,
false));
return RedirectToAction("/Vote?packetItemId=" + packetItemId +
"&votingType=" + votingType);
//return Json(new { isSuccess = true, statusMessage =
UserStringsService.VoteDeletedSuccessfully });
}
catch
{
Logger.LogError($"Error in deleting the Vote Id: {voteId}");
TempData.Put(key: TempDataKey.Vote.DeleteMessage,
StatusMessageModel.Create(UserStringsService.VoteDeleteFailed, false));
return RedirectToAction("/Discussion/Vote?packetItemId=" +
packetItemId + "&votingType=" + votingType);
//return Json(new { isSuccess = false, statusMessage =
UserStringsService.VoteDeleteFailed });
}
}
【问题讨论】:
标签: javascript html ajax asp.net-core