in Web Forms it was easy to register a script by this method, and to avoid duplicating a script you just use !IsStartupScriptRegistered() in and If statement.
how can you do this in MVC ?
Quite simple, you may accomplish some custom reder of js code . It may render teh content at the end of the page and mainatin a series of Key-value fierls. So when you make a cjeck for !IsStartupScriptRegistered() , use Key as parameter. Pretty simple. So I can mention here some custom implementations for this thing, but I wouln't :) try to do it by hand, I know you'll enjoy it! good luck
This may help, though it's more for script references than a startup script (read on to the section on resource tracking). http://stephenwalther.com/blog/archive/2008/08/22/asp-net-mvc-tip-36-create-a-popup-calendar-helper.aspx
I guess there isn't 1:1 copy of this functionality.
Some code:
<%@ Control Language="C#"
Inherits="System.Web.Mvc.ViewUserControl<IList<Item>>" %>
<script src="../src/preciousJavascript.js" type="text/javascript"/>
<%foreach (var item in Model){%>
<% Html.RenderPartial("_Item",item); %>
<%}%>
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Item>" %>
<%=Item.Name %>
Maybe this clears something