raranibar
raranibar

Reputation: 1267

inject javascript in head or body

In the file index.cshtml I need to inject JavaScript code, we developed the helper that is a library call in .net to load the JavaScript code that is in the dll .. We are doing this for safety reasons. The Helper code to call this function ToolBarControl the dll calls the next method I attached a piece of code.

private string RenderBarra() {
    StringBuilder JavaScript = new StringBuilder();
    JavaScript.AppendFormat(@"<script type= ""text/javascript"">{0}", Environment.NewLine);
    JavaScript.AppendFormat(@"var toolbar = new toolBarObject('toolbarObj');{0}", Environment.NewLine);
    ...
    ...
    JavaScript.AppendFormat(@"</script>{0}", Environment.NewLine);
    return JavaScript.ToString();
}

Html.ToolBarControl calling function to inject the script places the top (before of html head) I need to make this code in the header is injected into the head, body of the page or at the end

Note: the code javascript in the method RenderBarra works

Upvotes: 0

Views: 965

Answers (1)

Ilya Vinokurov
Ilya Vinokurov

Reputation: 145

Just create a simple html helper that will render the string Example: Html.RenderBarra()

Don't forget to render it as Raw text(@Html.Raw(your_helper))

Upvotes: 3

Related Questions