以下是我做到的。由於缺省WebGrid的有限性質,您只剩下幾個選項...我需要這個與IE6一起工作,並且找不到適用於所有瀏覽器的合適的jQuery插件,所以我選擇了選項1.警告:這是一個有點髒
1 - 滾你自己的HtmlHelper 2 - 使用第三方替代的WebGrid 3 - 使用jQuery插件
HtmlHelpers.cs
/// <summary>
/// This class contains various methods for supplementing the usage of html within the Razor view pages
/// </summary>
public static class HtmlHelpers
{
/// <summary>
/// This method truncates a string to a given length for display within a WebGrid or elsewhere as a tooltip
/// </summary>
/// <param name="helper">Generic parameter needed to recognize HtmlHelper syntax</param>
/// <param name="input">This is the string to truncate</param>
/// <param name="length">The length of the string to truncate to</param>
/// <returns>Html representing a tooltip, if needed</returns>
public static IHtmlString ToolTip(this HtmlHelper helper, String input, int length)
{
if (input.Length <= length)
return new MvcHtmlString(input);
else
return new MvcHtmlString(String.Format("<span title=\"{2}\">{0}{1}</span>", input.Substring(0, length), "...", input));
}
}
YourView.cshtml
grid.Column(columnName: "Detail", header: "Description", format: @<text>@Html.Truncate((string)item.Detail,50)</text>),
謝謝,我之前做過。雖然我剛剛構建了自己的簡單HTML表格,通過Jquery捕獲了mouseover事件,並在Ajax調用的幫助下獲得了數據。然後我把數據放入一個jQuery工具提示插件 – 2012-05-29 07:47:51