public static string Ratings(this HtmlHelper helper, Rating rate) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("<span class='rating' rating='{0}' title='Click to cast vote'>", rate.RatingID); const string formatStr = "<img src='/Content/images/{0}' alt='star' width='5' height='12' class='star' value='{1}' />"; for (Double i = .5; i <= 5.0; i = i + .5) { if (i <= rate.RatingID) { sb.AppendFormat(formatStr, (i * 2) % 2 == 1 ? "star-left-on.gif" : "star-right-on.gif", i); } else { sb.AppendFormat(formatStr, (i * 2) % 2 == 1 ? "star-left-off.gif" : "star-right-off.gif", i); } } sb.AppendFormat(" <span>Currently rated {0} by {1} people</span>", rate.RatingID, rate.Raters); sb.Append("</span>"); return sb.ToString(); }
public static string GetRatingHtml(Rating rate) { StringBuilder sb = new StringBuilder(); string path = HttpContext.Current.Server.MapPath("\\Images"); sb.AppendFormat("<span>"); string formatStr = "<img src='" + path + "\\{0}' alt='star' width='5' height='12' value='{1}' />"; for (Double i = .5; i <= 5.0; i = i + .5) { if (i <= rate.RatingID) { sb.AppendFormat(formatStr, (i * 2) % 2 == 1 ? "star-left-on.gif" : "star-right-on.gif", i); } else { sb.AppendFormat(formatStr, (i * 2) % 2 == 1 ? "star-left-off.gif" : "star-right-off.gif", i); } } //sb.AppendFormat(" <span>Currently rated {0} by {1} people</span>", rate.RatingID, rate.Raters); sb.Append("</span>"); return sb.ToString(); }