Javascript files display incorrectly in ASP.NET MVC?

I have a problem with javascript files on the main page ... I have the following:

                     

<script src="Scripts/jquery-1.2.6.min.js" type="text/javascript"></script>

<script src="Scripts/Plugins/jquery-corners.js" type="text/javascript"></script>

This works ... until I get deeper into the routes ... for example, it http://localhost/mywebsiteworks, but it http://localhost/mywebsite/actiondoesn't work - I lose all my imported javascript.

I have Url.Content for my images ... but it looks like I can't do anything for my javascript. It can't be that hard ... I'm missing something! Any help would be appreciated!

Update

I found the following Using scripts on the main page with ASP.NET MVC ... but I cannot get this to work if I set it between the tags ... where I need it. If I try to put it there, I get the following error:

The collection of controls cannot be modified because the control contains (i.e. <% ...%>).

+3
source share
2 answers

Found this out with other posts here on stackoverflow. Here is what finally worked:

<script src="<%= Url.Content("~/Scripts/CreativeLogic.js") %>" type="text/javascript"></script>
<script src="<%= Url.Content("~/Scripts/jquery-1.2.6.min.js") %>" type="text/javascript"></script>
<script src="<%= Url.Content("~/Scripts/Plugins/jquery-corners.js") %>" type="text/javascript"></script>

<script type="text/javascript"> 
    $(document).ready(function()
    {
        $('.part').corner("15px");
    });
</script> 
+4
source

Check UrlHelper.Content (can't find MSDN docs, sorry)

+1
source

Source: https://habr.com/ru/post/1704175/


All Articles