首页 > 解决方案 > 如何在同一个 asp razor 页面中有多个 post 处理程序?

问题描述

我正在创建一个论坛,人们可以在其中发布两种类型的帖子。如何让我的回复页面根据发送的参数响应 POST 请求?

我试过让每个函数都有不同的参数,但这并没有什么不同。我叫他们的唯一方法就是给他们两个都取名字OnPost。现在它给了我这个错误:

System.InvalidOperationException: Multiple handlers matched. The following handlers matched route data and had all constraints satisfied:

这是没有意义的,因为我正在发送(int, string, string, string)并且处理程序是:

OnPost(Int32, System.String, System.String, System.String)

OnPost(Int32, Int32, System.String, System.String, System.String)

标签: asp.nethttppostasp.net-core

解决方案


我认为你不应该有两个同名的 post 方法。您可以重命名其中一个并使用 javascript 发出自定义请求。


推荐阅读