找不到ASP核心路由POST页面

时间:2020-08-07 01:28:57

标签: asp.net-mvc asp.net-core asp.net-mvc-routing

我有标准的asp核心路由设置:

endpoints.MapControllerRoute(
    name: "areas",
    pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
endpoints.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");
endpoints.MapRazorPages();

然后我有4个动作(2个get和2个post):

public async Task<IActionResult> Edit(int? id)
{...}

[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(int id, CustomDTO customDTO)
{...}

public async Task<IActionResult> Review(int? id)
{...}

[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Review(int id, DifferentCustomDTO differentCustomDTO)
{...}

Review表格剃刀的开始如下:

<form asp-action="Review">

两个网址都看起来像这样:

https://localhost/MyController/Review/12

在正常情况下,POST操作将从URL值中获取其ID,并从表单的提交数据中获取CustomDTO。这一直有效,直到最近我才开始得到这个:

This localhost page can’t be found No webpage was found for the web address: 
https://localhost/MyController/Review/12
HTTP ERROR 404

我尝试从4个中删除2个,以查看是否存在某种冲突,但这并没有改变任何东西。 我如何找到自己搞砸的东西?

1 个答案:

答案 0 :(得分:2)

您需要在帖子正文中添加一些数据,因为如果使用此URL:

https://localhost/MyController/Review/12

然后,发布请求的HTML正文将为空。尝试将隐藏字段添加到表单中,例如:

@Html.HiddenFor(e => e.Id)
相关问题