Asp.net mvc script and style links

I am trying to include script and style references that will not be interrupted during deployment, however I cannot even get links to work locally. I tried using Url.Content() and MVCContrib <%=Html.ScriptInclude("")%> .

My scripts are in the Scripts folder in the root of the site; My styles are in the usual Content / css / folder.

The scripts look like this:

 <script type="text/javascript" src="/Scripts/MicrosoftAjax.debug.js" ></script> 

This will not work on the browse page in the Views folder. What am I doing wrong and what is the best way to handle this?

I would think that Url.Content() at least work for styles, but would be used on my main page, the link displayed

 <link href="/Content/css/Site.css rel="stylesheet" type="text/css" /> 

This does not work because the main page is in the shared folder, so what is really the way forward with this?

+4
source share
2 answers

<link href="<%= ResolveUrl("~/Content/css/Site.css")%>" rel="stylesheet" type="text/css" / >

works for your stylesheet. but if you are on MVC2 and you have files in the script directory, you can use the new helper:

 <%=Html.Script("scriptfile.js") %> 

this is better since you can also specify a file for release and debug mode:

 <%=Html.Script("scriptfile-min.js", "scriptfile.js") %> 
+5
source

I do it like this:

 <link href="<%= ResolveUrl("~/Content/css/Site.css")%>" rel="stylesheet" type="text/css" /> 

Also, take runat = server from your main tag if you do not want it to try to help you.

(Edit - fixed inappropriate quote)

Update:. To clarify, I have this work in development (localhost: 1227, root), on my test server (full domain, root) and in production (in another domain, in a subdirectory). Works great in every case!

0
source

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


All Articles