I've an extension method in C# that creates a script, then puts the created script into a view. I want put the created script into a .js file then reference the .js file to the view. Is there a way to do so?
C# code:
public static HtmlString RenderScript(this IHtmlHelper htmlHelper)
{
var builder = new StringBuilder();
string script = string.Empty +
"<script type=\"text/javascript\" >" +
//do something
" </script>";
builder.AppendLine(script);
return new HtmlString(builder.ToString());
}
View:
@section Scripts{
@(Html.RenderScript())
}