I have 2 PartialViews inside a parent View.
In these 2 PartiaViews I generate some JavaScript code which needs to be included to the bottom of the parent View.
Here is the HtmlHelper extension which generates some JavaScript in the PartialViews.
public static MvcHtmlString KO_ObjectFor<TModel>(this HtmlHelper<TModel> htmlHelper)
{
String str = "some javascript code";
return MvcHtmlString.Create(str);
}
This is the parent View (main View)
...
//First Partial View
<% Html.RenderPartial("_PartialViewFirst"); %>
//Second Partial View
<% Html.RenderPartial("_PartialViewSecond"); %>
//Here I need to display the JavaScript from the PartialViews
<script type="text/javascript">
<%: Html.FunctionToConcatenateJavaScript() %>
</script>
...
What would be the right approach?
You could use a Stack to push and pop scripts in the HttpContext:
then you could push:
and then pop em all in the master: