簡體   English   中英

如何在 ASP.NET MVC 中記錄鼠標懸停的工具提示中顯示來自數據庫字段的附加信息

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

我在表格中顯示產品代碼列表,每個產品都有自己的尺寸。 我希望能夠懸停產品並能夠查看它們自己的尺寸。 我對這個實現的方法不起作用。 我需要幫助。 提前致謝

視圖模型

  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();
    }

看法

  <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>

為了解決我的問題,我必須引用完整的表格而不是字段本身,這使我可以更輕松地在工具提示中顯示我想要查看的數據。

 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>
                    }
                }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM