Home >Backend Development >C++ >Can ASP.NET MVC Controller Methods Be Overloaded, and If Not, How Can I Achieve a Similar Result?
ASP.NET MVC controller method heavy load and alternative scheme
Question:
ASP.NET MVC controller can re -load method? Why did my heavy load attempt failed? The error message I received is:
"The current request of the" MyMethod "operation on the" controller type 'mycontroller' is not clear between the following operations: "
Answer:
Although the error message indicates that the method is not supported, the feature can achieve similar effects.
In ASP.NET MVC, the method is not allowed to be loaded in the same controller. However, you can use the feature to specify different names. This allows you to sign different methods for operations with the same HTTP method (such as GET or POST). [ActionName]
features to the method to rename. For example: [ActionName]
It should be noted that the use of [ActionName]
is not a real heavy load method. It only changed the operation name of the route to the method. Therefore, you still need to use different operation names for the same HTTP method.
<code class="language-csharp">[ActionName("MyOverloadedName")] public ActionResult MyMethod(int id) { // 重载方法的代码 }</code>For more information, please refer to Phil Haack's article:
https://www.php.cn/link/8AB84C57BF23BF8330B47C2DB1 [ActionName]
The above is the detailed content of Can ASP.NET MVC Controller Methods Be Overloaded, and If Not, How Can I Achieve a Similar Result?. For more information, please follow other related articles on the PHP Chinese website!