How to simulate IsStartupScriptRegistered in ASP.NET MVC

it was easy to register a script in Web Forms with this method, and to avoid script duplication you just use IsStartupScriptRegistered () in and If statement.

how can you do this in MVC?

+1


a source to share


3 answers


Simple enough, you can do some custom js code changes. It can display content at the end of the page and mainatin a series of Key-value fierls. So when you do cjeck for! IsStartupScriptRegistered (), use the Key as parameter. Pretty simple. So I can mention some custom implementations here for this thing, but I don't want to :) try to do it manually, I know you will like it! good luck



+1


a source


I assume there is no 1: 1 copy of this feature.

Some codes:



<%@ 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 it clears something

0


a source


It might help, though more for script references than running the script (read the section on resource tracking). http://stephenwalther.com/blog/archive/2008/08/22/asp-net-mvc-tip-36-create-a-popup-calendar-helper.aspx

0


a source







All Articles