In mvc instead of using the code behind (action), typically you would add the script in the view. You might place an indicator in model or view bag.
Also as it now common to add library scripts at the end of the html rather than head, the layout typically defines a scripts section that view can use to have the script render after the library includes.