I'm a little late to the MVC game and frankly there is so much information out there, it's almost impossible to use the "right" keywords to even get close to an answer.
I have a function that gets codes
from the database and displays them in an auto-complete list. I want to share this GetCodes
method between Controllers and these codes
are used on other forms.
What is the best MVC
practice for this?
Is it better to make a base class with this function, or is it better to create a Web API Controller to share these type of methods?
[Edit]
To clarify, the codes
I'm providing auto-completing for are like a list of cities in a large state or province. It's a static list that is only updated by the government when a change happens at the federal level.
I just don't want to cut/paste the function that performs the search, I'd rather write something that is reusable. Right now, the function GetCodes
lives on one Controller and I call that controller Action method from other parts of the site. I don't like this and I'm looking for some advise on how to use other parts of ASP.NET to accomplish this in a better more robust way.
Thank you