Someone ask following question to me in interview, to which I cannot able to answer. Somebody please help me.
Can we create Static ActionResult method in controller? If yes. What is the benifits? and if no. What is the reason?
If "ActionResult method" is a method that returns ActionResult, you can declare it static, of course, but it will not be called when you initiate that action. When calling some action, ASP.NET MVC creates an instance of the controller (using ControllerFactory), and since your method is static, it is not related to any instance, and thus, it will not be called by MVC
Don't think it is a good idea to create a static action method, as you will no longer have access to all the controller properties, such as controllercontext, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With