I have a partial view (UserControl) that implements a simple pager in my Asp.Net MVC project. This pager needs access to a .js file that needs to be included exactly once, regardless of how many instances of the pager control are present on the parent page.
I’ve tried to use Page.ClientScript.RegisterClientScriptInclude, but it had no effect (I assume because the code nugget was evaluated too late to impact the head control). Is there any simple alternative?
Set a flag in HttpContext.Current.Items when you send the script in your partial – it’s a dictionary that lingers for the whole request. E.g.:
This way it’ll be rendered at most once.