views:

22

answers:

1

I am working on an MVC site that contains overloaded controllers that accept variable parameters. Depending on the parameter count (mysite/{id}) versus (mysite/{id}/{name}/{state}) the relative paths to resources change.

The same view may be used by different controllers. How do I best address resources such as script libraries or images?

<img src="../../Content/Images/Fred.png" />

or

<img src="../../../Content/Images/Fred.png" />

Can this be accomplished using paths relative to the root instead of the current view? Does something like "~/" exist in MVC? Or should I use a separator other than the forward slash in the URLs of my pages (controllers & views).

+3  A: 

Use the built-in MVC URL helper like so:

<script src="<%= Url.Content("~/Scripts/jquery-1.3.2.min.js")%>" type="text/javascript"></script>
Tahbaza