Correct way to reference Javascript in ASP.NET MVC?

前端 未结 5 1649
孤城傲影
孤城傲影 2020-12-29 07:27

What is the correct way to reference Javascript in ASP.NET MVC? Using something like ../../Scripts/Myscript.js seems to work fine for routes that are the traditional {contro

5条回答
  •  情歌与酒
    2020-12-29 07:34

    I've created my own HtmlHelper extensions that look like:

    public static string MEScriptBlock(this HtmlHelper html, string path, string releasePath)
    {
    #if DEBUG
    #else
        if (!string.IsNullOrEmpty(releasePath))
            path = releasePath;
    #endif
    
        return string.Format("\r\n",
                             path);
    }
    

    If intellisense is what you're after you could trick VS into thinking that a JS file has been loaded... E.g.

    <% if (false)
       { %>
        
    <% } %>
    

    HTHs, Charles

提交回复
热议问题