简体   繁体   English

行动 function 订单事项在.Net Core Controller

[英]Action function order matters in .Net Core Controller

I have encountered something odd about the actions order in a controller.我在 controller 中的操作顺序遇到了一些奇怪的问题。 Here is the first case:这是第一种情况:

[HttpGet]
[Route("/account/notification")]
public IActionResult NotificationSettings()
{
...
}

[HttpPost]
[Route("/account/notification")]
[ValidateAntiForgeryToken]
public IActionResult NotificationSettings(NotificationSettingsModel model)
{
...
}

In this case, the post function isn't called from the form post action.在这种情况下,不会从表单发布操作调用发布 function。 But in the second case it's called.但在第二种情况下,它被称为。

[HttpPost]
[Route("/account/notification")]
[ValidateAntiForgeryToken]
public IActionResult NotificationSettings(NotificationSettingsModel model)
{
...
}

[HttpGet]
[Route("/account/notification")]
public IActionResult NotificationSettings()
{
...
}

Simply, changing the order of functions in the controller changes the behaviour of the actions that is invoked in controller.简单地说,更改 controller 中的函数顺序会更改 controller 中调用的操作的行为。 Can someone explain or guide me about this?有人可以解释或指导我吗?

Basically / overrides the route declared on the controller.基本上/覆盖在 controller 上声明的路由。 You can refer this document https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/routing?view=aspnetcore-3.1#attribute-routing-for-rest-apis您可以参考此文档https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/routing?view=aspnetcore-3.1#attribute-routing-for-rest-apis

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM