我有一个方法需要被各种 Controller 和各种 Action 调用。放置此方法的正确位置在哪里以及我如何从其他 Controller 调用它。似乎无法通过搜索找到任何东西,所以如果有人能指出我正确的方向,我将不胜感激。
谢谢
最佳答案
听起来像是基本 Controller 的工作:
public class BaseController : Controller
{
// Do your common stuff here...
}
然后继承BaseController
:
public class MyController : BaseController
{
// Your code goes here...
}
关于c# - MVC4 中的全局方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20452706/