This is a migrated thread and some comments may be shown as answers.

ScriptRegistrar() and embedded javascript

1 Answer 81 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Andrew
Top achievements
Rank 1
Andrew asked on 20 Oct 2011, 11:50 AM
Hopefully a simple one.

I have used Teleriks Registrar to include all the javascript files, and have correctly added to just before the end of the body element. On the partial views that need specialised javascript, I use the registrar again to add those files prior to calling render on the registrar.

However. If I want to include some javascript embedded on the page rather than in an external file - how would I do this? 

The embedded javascript is dependant on some of the external javascript files that are rendered at the bottom of the page so I cannot include them normally.

Any clues?

1 Answer, 1 is accepted

Sort by
0
Florian
Top achievements
Rank 1
answered on 09 Jan 2012, 08:39 AM
I found this in the HtmlHelperExtensions from Telerik i suppose you can do the same where ever you want as long as you have access to the httpContext.

ViewContext viewContext = htmlHelper.ViewContext;
            HttpContextBase httpContext = viewContext.HttpContext;
            ScriptWrapperBase scriptWrapper = DI.Current.Resolve<ScriptWrapperBase>();
            ScriptRegistrar component2 = httpContext.Items[(object)ScriptRegistrar.Key] as ScriptRegistrar ?? new ScriptRegistrar(new WebAssetCollection(WebAssetDefaultSettings.ScriptFilesPath), (IList<IScriptableComponent>)new List<IScriptableComponent>(), viewContext, DI.Current.Resolve<IWebAssetCollectionResolver>(), scriptWrapper);
ScriptRegistrarBuilder scriptRegistrar = ComponentBuilderBase<ScriptRegistrar, ScriptRegistrarBuilder>.Create(component2);
scriptRegistrar.ToRegistrar().Scripts.Add("some.js");
Tags
General Discussions
Asked by
Andrew
Top achievements
Rank 1
Answers by
Florian
Top achievements
Rank 1
Share this question
or