如何在 ASP.NET MVC 中的记录鼠标悬停工具提示中显示来自数据库字段的附加信息

How to display additional information from a database field in tool tip on Mouse Over of record in ASP.NET MVC

我在 table 中显示产品代码列表,每个产品都有自己的尺寸。我希望能够悬停在产品上并能够查看它们自己的尺寸。我对这个实现的方法没有奏效。 我需要帮助。提前致谢

ViewModel

  public class PTGIndexVM
{
    [Display(Name="Select Promotion")]
    public int PromotionId { get; set; }
    public List<SelectListItem> PromotionOptions { get; set; }
    public IList<EditPTG> IndexList { get; set; }
    public IList<String> ProductCodes { get; set; }
    public string wrapClass { get; set; }

    public List<SelectListItem> Size { get; set; }


    public PTGIndexVM()
    {
        IndexList = new List<EditPTG>();
        PromotionOptions = new List<SelectListItem>();
        ProductCodes = new List<String>();
        Size = new List<SelectListItem>();

        Setup();
    }

View

  <fieldset class="fieldset">
        <legend class="legend">Product To Grade Mappings</legend>
        <table class="promo full-width alternate-rows">
            <tr>
                <th>
                    @Html.DisplayNameFor(model => model.IndexList[0].grade.GradeString)
                </th>
                <th class="center-text">Frequency
                </th>
                @if (Model.IndexList.Count > 0)
                {
                    foreach (var code in Model.ProductCodes)
                    {

                    <th class="center-text" title="@Model.Size.">
                        @Html.DisplayFor(m => code)



                    </th>

                    }
                }
                <th>Actions</th>
            </tr>

在 foreach 循环中为什么不使用代码而不是模型,考虑到模型中有一个名为 Size 的字段。

<th class="center-text" title="@code.Size">
   @Html.DisplayFor(m => code)
</th>

为了解决我的问题,我不得不引用完整的 table 而不是字段本身,这让我更容易在工具提示中显示我想看到的数据。

 public class PTGIndexVM
{
    [Display(Name="Select Promotion")]
    public int PromotionId { get; set; }
    public List<SelectListItem> PromotionOptions { get; set; }
    public IList<EditPTG> IndexList { get; set; }
    public IList<Product> Products { get; set; }
    public string wrapClass { get; set; }

    /// <summary>
    /// Members Setup
    /// </summary>
    public PTGIndexVM()
    {
        IndexList = new List<EditPTG>();
        PromotionOptions = new List<SelectListItem>();
        Products = new List<Product>();
        Setup();
    }

  vm.Products = productLogic
            .GetByAndInclude(x => x.PromotionID == PromotionId && x.WindowProduct == true && x.Active == true, new List<string>() { "Size", "ProductTemplate" })
            .Where(prod => allPTG.Any(x => x.ProductID == prod.ProductID))
            .OrderBy(prod => prod.ProductCode)
            .Select(prod => prod)
            .ToList();

 foreach (var product in Model.Products)
                    {
                    <th class="center-text" title="@product.ProductTemplate.Vertical (V) x @product.ProductTemplate.Horizontal (H)">
                        @Html.DisplayFor(m => product.ProductCode)
                    </th>
                    }
                }