Hi,@mc ,
there's the concept of CSS isolation,you could check this document,but it will only work for css files
In MVC projects, if your views share the same layout,you could try to get the name of current controller and action from viewcontext and bind the js source as below:
in layout:
@{
var action = ViewContext.RouteData.Values["action"].ToString();
var controller = ViewContext.RouteData.Values["controller"].ToString();
var source = string.Format("https://localhost:5001/js/{0}.js", action);
}
<script src=@source></script>
Index.js:
window.onload = function () {
alert("Index")
}
Privacy.js:
window.onload = function () {
alert("Privacy")
}
Result:
In RazorPage,you could try ViewContext.RouteData.Values["page"].ToString()
----------
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards
RuikaiFeng