Note that there are some explanatory texts on larger screens.

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

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload