i just wrote some helpers for images you can use.
(1) simply create a public static class called AppHelper with a using System.Web.Mvc;
and add it to a folder in your MVC project called 'Helpers'.
(2) copy in these methods:
public static string Image(this HtmlHelper helper,
string classText, string sourcePath, string altText, string width, string height)
{
return Image(helper, classText, sourcePath, altText, width, height, null);
}
public static string Image(this HtmlHelper helper,
string classText, string sourcePath, string altText, string width, string height, object htmlAttributes)
{
StringBuilder sb = new StringBuilder();
if (htmlAttributes != null)
foreach (PropertyInfo p in htmlAttributes.GetType().GetProperties())
sb.AppendFormat(@" {0}=""{1}""", p.Name, p.GetValue(htmlAttributes, null).ToString());
if (htmlAttributes == null)
return String.Format(@"<img{0} src=""{1}"" alt=""{2}"" width=""{3}"" height=""{4}"" />",
String.IsNullOrEmpty(classText) ? String.Empty : String.Format(@" class=""{0}""", classText),
(new UrlHelper(helper.ViewContext.RequestContext)).Content(sourcePath),
altText, width, height);
else
return String.Format(@"<img{0} src=""{1}"" alt=""{2}"" width=""{3}"" height=""{4}""{5} />",
String.IsNullOrEmpty(classText) ? String.Empty : String.Format(@" class=""{0}""", classText),
(new UrlHelper(helper.ViewContext.RequestContext)).Content(sourcePath),
altText, width, height, sb.ToString());
}
(3) ..and use like so:
<% =Html.Image("small_pic_border","~/Content/Images/Home/office2_137x139.jpg","principal headshot","137","139") %>
This method uses the Url.Content method that liammclennan mentioned. It should also force you into some good habbits: like using alternate text etc.
For scripts use:
<script type="text/javascript" src="<% =Url.Content("~/Scripts/mootools.js") %>"></script>