gpt4 book ai didi

c# - 扩展 ApiController

转载 作者:太空宇宙 更新时间:2023-11-03 20:18:45 25 4
gpt4 key购买 nike

正如标题所示,我想扩展 ApiContoller 类以包含一些自定义属性和辅助方法,但每当我尝试将它用于 Controller 时,我都会收到消息 Multiple actions were found that match the request:

示例代码:

public class ExtendedApiController : ApiController {
public string SomeHelper() {
....
}
}

public class AccountController : ExtendedApiContoller {
public void Post (ModelObject obj){
string x = SomeHelper();
...Bunch of business logic
}
}

出于某种原因,Web Api 似乎不喜欢我这样做,或者我需要覆盖其他一些基本方法。我能看到的唯一其他选择是将扩展方法附加到 ApiContoller,但我想尽可能避免这种情况。

有什么想法吗?

最佳答案

您可以使用[NonAction] 属性:

public class ExtendedApiController : ApiController {

[NonAction]
public string SomeHelper() {
....
}

}

更多信息 here, at the bottom of the page .

关于c# - 扩展 ApiController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15002025/

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