user2227904
user2227904

Reputation: 679

MVC How to make controller inherit functions?

I am new to the .NET MVC and I was trying to implement functions I had in my previous work on WebForms. I want to extend the normal controller, so that I have a preset of functions and/or variables built in and ready for use in any controller. Is that possible or should I use a model every time I need those functions/variables?

Upvotes: 0

Views: 127

Answers (1)

JuChom
JuChom

Reputation: 6009

Create a directory Infrastructure in you MVC project,

Add a class called BaseController that inherits from Controller and add your method in this class

Now, all your controller in your Controller directory should inherit from BaseController instead of Controller.

Upvotes: 3

Related Questions