Resource addressing in MVC applications
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 r开发者_开发技巧elative 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).
Use the built-in MVC URL helper like so:
<script src="<%= Url.Content("~/Scripts/jquery-1.3.2.min.js")%>" type="text/javascript"></script>
精彩评论