1

in view, i have at the bottom many javascript and jquery code, and i dont like it, so im placing all scripts into one ascx file, and make partial rendering like:

<!--<%Html.RenderPartial("~/Views/Home/StationLogics.ascx"); %>-->

of this ascx file with scripts. So, is there any better way?

cant place it to master page, cause not always i need this scripts, if user get some privilage, he can use some scripts, if not - others

2 Answers 2

1

it mat not be what u intended to know but i think that u can place all ur javascript and jquery code in a js file like in yourjavascript.js file and place a reference of js file in your view or the master page page file that the view is inheriting e.g.

<script src="<%=ResolveUrl("~/scripts/yourjavascript.js") %>" type="text/javascript"></script>
Sign up to request clarification or add additional context in comments.

Comments

0

You could add your common JavaScript files in the head element of a Master page, and then let your pages reference that master page using the <%@ Page %> directive, for example:

<%@ Page MasterPageFile="/Views/Shared/Site.Master" %>

Now, all you have to do is update the scripts in your master page, and pages referencing that master page will have the scripts as well.

However, if your scripts are too specific to include in the master page, then your solution is probably fine.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.