chugh97
chugh97

Reputation: 9992

MVC (Not Using Razor) - How to remove scripts files in master page to ascx control and use them

I have MVC app using traditional aspx views not Razor. I have a bunch of blocks of js files references in Master file. I ideally want to move them somewhere else so I can just reference them will just one line in the master file. How can this be achieved?

Upvotes: 0

Views: 568

Answers (1)

Tommy
Tommy

Reputation: 39827

Create a partial view (I will call mine MyPartialViewWithScripts) and place it in your shared directory. In this partial view, list out all of the javascript files that you need/want to display in the master layout. Then in your master layout call

Partial View

<script type="text/javascript" src="PathToJSfile.js"></script>
<script type="text/javascript" src="PathToJSfile2.js"></script>

Master Layout

<html><head>
<% Html.RenderPartial("MyPartialViewWithScripts")%>
</head>

Upvotes: 1

Related Questions