2012-02-13 58 views
1

我在我的View.I中有一個MVC3 WebGrid,當鼠標懸停在任何行上時顯示工具提示,顯示來自服務器的信息。我已經看到這個鏈接: Show a tooltip with more info when mousover a MVC3 Razor WebGrid row顯示MVC3中的鼠標懸停事件的工具提示WebGrid

我的觀點是,我將如何獲得該行在鼠標懸停事件的ID,因爲來自服務器的信息將基於行ID或可能計數。此外,在此鏈接中: http://www.lullabot.com/files/bt/bt-latest/DEMO/index.html 您需要某個選擇器來顯示工具提示。我如何爲WebGrid的每一行分配一個類,以便我可以顯示工具提示?

回答

1

以下是我做到的。由於缺省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>), 
+0

謝謝,我之前做過。雖然我剛剛構建了自己的簡單HTML表格,通過Jquery捕獲了mouseover事件,並在Ajax調用的幫助下獲得了數據。然後我把數據放入一個jQuery工具提示插件 – 2012-05-29 07:47:51

相關問題