Previously, with the standard .NET platform, we were able to include CSS and JS files based on action and controller names using code like this:
string scriptSource = Url.Content(string.Format("~/js/page/{0}/{1}.js", controllerName, actionName));
if (System.IO.File.Exists(Server.MapPath(scriptSource)))
{
<script type="text/javascript" src="@scriptSource"></script>
}
We would insert these codes in the Layout and it worked as long as the js folder and file names matched the controller and action names.
Recently, I upgraded the project to .NET Core (2.1) and implemented dependency injection in the BaseController to access the Server.MapPath value. However, I encountered difficulties reaching from the _Layout view to the BaseController or codebehind to get Server.MapPath. If anyone has successfully accomplished this, please share your solution.