Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我是 .NET MVC 的新手,我试图实现我之前在 WebForms 上的工作中的功能。我想扩展普通控制器,这样我就可以在任何控制器中使用预设的函数和/或变量。这是可能的还是每次我需要这些函数/变量时都应该使用模型?
在 MVC 项目中创建一个目录 Infrastructure,
添加一个继承自 Controller 的名为 BaseController 的类,并在此类中添加您的方法
现在,Controller 目录中的所有控制器都应该继承自 BaseController 而不是 Controller。