我们可以创建控制器的静态方法的ActionResult? [英] Can we create Static ActionResult method in Controller?

查看:208
本文介绍了我们可以创建控制器的静态方法的ActionResult?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人问以下问题对我的采访,向我不能能回答。有人请帮助我。

Someone ask following question to me in interview, to which I cannot able to answer. Somebody please help me.

我们能创建静态的ActionResult在控制器方法?
如是。什么是典型应用该类超支?如果没有。原因是什么?

Can we create Static ActionResult method in controller? If yes. What is the benifits? and if no. What is the reason?

推荐答案

如果ActionResult的方法是返回的ActionResult的方法,你可以声明为静态的,当然,但是当你开始的行动将不会被调用。当调用一些动作,ASP.NET MVC创建控制器(使用的ControllerFactory)的一个实例,并且因为你的方法是静态的,它是不相关的任何实例,因此,它不会受到MVC称为

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

这篇关于我们可以创建控制器的静态方法的ActionResult?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆