【问题标题】:How display the last n of records in MVC如何在 MVC 中显示最后 n 条记录
【发布时间】:2016-01-16 06:05:49
【问题描述】:

我正在服用最后 4 个 4 个 cmets,并希望在工具提示中显示, 我正在执行以下代码,但它显示的内容类似于"System.Collection.Generic.List"

var list = db.PO_Prd_Comments.Where(t => t.PO_TrgCal_ID == item.ID && t.Reply == false).OrderByDescending(t => t.PO_TrgCal_ID).Take(4).ToList();
List<string> comments = new List<string>();
if (list.Count != 0)
{
    foreach (var ts in list)
    {
        comments.Add(ts.PrdComment);
        if (list.Count == 1)
        {
            notify = list.SingleOrDefault().notify;
        }
        else
        {
            notify = true;
        }                                      
    }                                                  
} 

<td>
    <a href="#" onclick="popup4(@CountID)" title="@comments"
    <img src="~/Images/comment.GIF"/></a>
</td>

我如何在工具提示中显示这四个 cmets。

【问题讨论】:

  • 但是在视图中,请帮助我如何放入列表然后显示
  • 举个相关的例子

标签: asp.net-mvc-4 razor


【解决方案1】:

comments 是一个字符串列表。您需要将其转换为单个字符串并将其用作标题属性值。

<a href="#" onclick="popup4(@CountID)" title="@String.Join(Environment.NewLine,comments)">
     <img src="~/Images/comment.GIF"/>
</a>

【讨论】:

    猜你喜欢
    • 2018-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-24
    • 2015-04-29
    相关资源
    最近更新 更多