![](/img/trans.png)
[英]Routing: The current request for action […] is ambiguous between the following action methods
[英]Action Routing: Application gets confused between the GET and POST methods
内容:
此时,使用GET方法构造的视图需要两个参数: id
和date
。 在此视图中,存在一个表单,该表单使用参数id
通过POST方法将信息发送回Controller
GET方法
[HttpGet]
public async Task<IActionResult> DetailsAdmin(int? id, [ModelBinder(typeof(PModelBinder))]DateTime? date)
{
{...}
}
开机自检方法
[HttpPost, ActionName("DetailsAdmin")]
[ValidateAntiForgeryToken]
[Route("HechosLiquidadors/DetailsAdmin/{id}")]
public async Task<IActionResult> DetailsAdmin(int? id)
{
{...}
}
问题:
当视图内的表单将信息发送到控制器时,它将进入GET操作而不是POST操作。
表格:
<form id="@(String.Format("{0}{1}","form",Model[i].HechosID))"
asp-action="DetailsAdmin" method="post" asp-route-id="@Model[i].HechosID" ></form>
我试过使用自定义路由到POST操作方法,但是没有运气。 我该如何纠正这个问题,以便表单正确指向POST操作?
在这两种操作方法中,所有参数都是可选的。 因此,Mvc无法选择“最佳候选”方法来执行。 更改如下第一个操作,并检查ID不为0:
[HttpGet]
public async Task<IActionResult> DetailsAdmin(int id = 0, [ModelBinder(typeof(PModelBinder))]DateTime? date)
{
if (id != 0)
{
}
{...}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.