Why use Url.Content for referencing resources?

隐身守侯 提交于 2019-12-05 11:44:44

What you have works the same as Url.Content(). Url.Content() is just like adding a ~ to be beginning of your paths:

<script src="~/Scripts/jquery.js" type="text/javascript"></script>

Just ensures the path is always correct with routing. You can also make a Html helper method to make this easier:

public static string RenderScript(this HtmlHelper htmlHelper, string file) {
            var f = file.EndsWith(".js") ? file : string.Concat(file, ".js");
            return string.Format("<script src=\"/public/scripts/{0}\" type=\"text/javascript\"></script>", f);
        }

Then you can just put this in your masterpage:

<%=Html.RenderScript("jquery")%>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!