gpt4 book ai didi

c# - 在与请求匹配的 Controller 上未找到任何操作

转载 作者:可可西里 更新时间:2023-11-01 03:14:07 24 4
gpt4 key购买 nike

请原谅我在这方面的无知。我已经阅读了很多线程,但仍然无法正确设置路由。

我有一个这样的 ProductsController:

public class ProductsController : ApiController
{
[ActionName("GetListOfStudents")]
public static List<Structures.StudentInfo> GetListOfStudents(string Username, string Password)
{
List<Structures.StudentInfo> si = StudentFunctions.GetListOfStudents(Username, Password);
return si;
}
}

我有一个控制台测试程序,我在其中定义了路由:

config.Routes.MapHttpRoute(
name: "ApiByAction",
routeTemplate: "api/products/GetListOfStudents",
defaults: new { controller = "products", action = "GetListOfStudents" });

但是当我运行调用时

GET http://localhost:8080/api/Products/GetListOfStudents

我收到错误信息:

MessageDetail=No action was found on the controller 'Products' that matches the name 'GetListOfStudents'.

我一直在苦苦思索,想不出正确的路线。

有好心人愿意帮助我吗?

最佳答案

好的 - 感谢您的帮助!

这是我为让它工作所做的:

  1. 从 GetListOfStudents 函数中删除了“静态”。
  2. 添加了以下路线。
config.Routes.MapHttpRoute(
name: "ApiByAction",
routeTemplate: "api/products/GetListOfStudents/{username}/{password}",
defaults: new { controller = "products", action = "GetListOfStudents" }
);

感谢大家的帮助!

关于c# - 在与请求匹配的 Controller 上未找到任何操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22914928/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com