I've recently been working on a project and I've been seeing two different forms of url's being used.
src="../MyLinkUrl"
and
src="/MyLinkUrl"
We are using MVC .NET and the times I have seen the .. usages have been in Javascript code files and not when it's been generated by the MVC URL helpers. Typically the usages range from specifying a controller action to specifying images.
Both seem to work but I'm wondering which is the better practice or if it depends on the context. Some questions I have are:
- What benefits/pitfalls does one have over the other
- Is one better practice than the other
- Does it depend on context and if so what context?
../MyLink
mean that my link is in the parent directory of the working directory, while/MyLink
is in the working directory./MyLink
is an absolute path. You're thinking ofMyLink
, which is a relative path in the current directory/level (and is the same as./MyLink
)