Why did Asp.net MVC team choose "../../Content/Site.css" rather than "~/Content/Site.css" in Site.Master page?
<link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
The above code shows an external css inclusi开发者_如何学运维on tag declared in Site.Master template.
My question: why did the Asp.net MVC team choose that way rather than using "~/Content/Site.css" ?
Is it the best practice? I am sorry, I am a newbie and still learning to improve my skill.
EDIT 1: I want to make it clearer that "~/" must be passed in to url-resolving method first. Thus, I can rewrite my question as follows:
Why did the team choose "../.." rather than "~/" resolved by url resolver?
Refer to what @Pauli Østerø said. But, since you asked for a best practice, here it is .. get rid of those hardcoded strings. Use T4MVC for those paths
~ is a asp.net thing and doesn't make sense in pure html. In webforms that is handled by turning the tag into a server control, that can translate ~ into a absolute path, while you in MVC would have to call some method yourself. Some method being Server.MapPath
for instance
Or use "/Content/Site.css", as "/" denotes the site root in html.
This issue has been fixed by MVC 3 as follows: I think the MVC team has read this question :-)
<head>
<title>@ViewBag.Title</title>
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript"></script>
</head>
精彩评论