asp.net - 如何在同一个 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)
解决方案
我认为你不应该有两个同名的 post 方法。您可以重命名其中一个并使用 javascript 发出自定义请求。
推荐阅读
- c++ - Win10创建windows共享时的UAC
- flutter - Flutter 中的 Either 模块中的 Left 和 Right 是什么?
- powershell - 根据操作系统版本进行注册表更改
- javascript - 猴子补丁 XMLHttpRequest.send 用于特殊 url
- amazon-web-services - 用于管理无 AWS 服务器的基础设施的 Terraform 或云形成
- python - 如何在 Django 中对空白字段表单进行单元测试?
- flutter - 消费者完成构建后颤振 showDialog
- jmeter - 将变量从一个 jdbc 请求发送到 JMeter 中的另一个 jdbc 请求
- grails - 创建名为 samlAuthenticationProvider 的 bean 时出错?
- python - 在 JSON 中转换 Python 列表