Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8327153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:00:35+00:00 2026-06-09T01:00:35+00:00

In a partial view I load a javascript file like this : <script src=@Url.Content(~/Scripts/Testing.js)

  • 0

In a partial view I load a javascript file like this :

<script src="@Url.Content("~/Scripts/Testing.js")" type="text/javascript"></script>

In the Testing.js, there are some functons defined
That’s work, the functions defined in the file can be used.

Now I do an action in my application, my controller return an another (where I don’t load any js file) partial view. The functions defined in Testing.js are still available in this partial view.

Is there a way to “remove” the functions loaded in the first view ?

Thanks,

Update 1

I tried this in the partial view but error :
The file “~/Views/xxxx.cshtml” cannot be requested directly because it calls the “RenderSection” method.

@section MyScript {
    <script src="@Url.Content("~/Scripts/Testing.js")" type="text/javascript"></script>
}
@RenderSection("MyScript", false)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T01:00:37+00:00Added an answer on June 9, 2026 at 1:00 am

    You should avoid referencing any scripts in partials. You could define a section in your Layout, for example just before the closing </body> which will allow for views to include some custom scripts:

        <script type="text/javascript" src="@Url.Content("~/scripts/some_common_script_that_will_be_used_by_all_views_such_as_jquery_for_example")"></script>
        @RenderSection("scripts", false)
    </body>
    </html>
    

    and then in the view (not in the partial view) override this section to include any scripts that this view might need:

    @section scripts {
        <script src="@Url.Content("~/Scripts/Testing.js")" type="text/javascript"></script>
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in my view, I use content_for to load a partial (a javascript file). I'd
How can i dynamically load a Partial View? I mean I have this view,
I have a partial view that has something like this <%= Html.DropDownListFor(m => m.SelectedProductName,
In a javascript file, I pull off this rails variable from my view: this.main_id
I am using Ajaxy Call to load the partial view. It is working fine
How can I load a page or a partial view in the popup window
I have a partial view which renders a table. On page load, I am
So, I have a page that looks like the following: alt text http://img704.imageshack.us/img704/5973/croppercapture3.png This
I have my main view like this: <%@ Page Title= Language=C# MasterPageFile=~/Views/Shared/Site.Master Inherits=System.Web.Mvc.ViewPage %>
asp.net mvc 3 with razor I have a script inside a partial view <script

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.