Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Why not just send the dates down as is and use a JS plugin like <a href="http://timeago.yarp.com/" rel="nofollow">TimeAgo</a> e.g.</p> <pre><code>public PartialViewResult MostRecentMembersPosts() { return PartialView("pvMostRecentMembersPost", _imf.DisplayMostRecentForumPosts().ToList()); } </code></pre> <p>Then in your view</p> <pre><code>@model IEnumerable&lt;MemberForumProperties&gt; &lt;!-- Head section would need to be defined in your master page first --&gt; @section Head { &lt;script src="jquery.timeago.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $.ready(function() { $("abbr.timeago").timeago(); }); &lt;/script&gt; } @foreach (var m in Model) { &lt;abbr class="timeago" title='@m.ForumMemberDateTimePostedPost.ToString("s")' /&gt; } </code></pre> <p>TimeAgo will take care of converting your <code>DateTime</code> values into a fuzzy timestamp.</p> <hr/> <p><strong>The Problem</strong></p> <p>If you don't want to go for the client-side approach, then to fix your current server-side issue you need to send down a list of relative times, at the minute you only appear to be sending down the <em>last</em> relative time i.e.</p> <pre><code>var test = ""; foreach (MembersForumProperties t in loopThroughDateTimes) { test = t.ForumMemberDateTimePostedPost; } // test now contains the date/time of the last item in the `loopThroughDateTimes` list var membersMostRecentPost = new MostRecentPostsViewModel { SelectMostRecentForumPosts = displyMostRecentForumPosts, DateAndTimeOfForumPosts = IsPostLessThanOneHour.DisplayPostInMinutesOrSeconds(test) }; // DateAndTimeOfForumPosts only contains the relative string for the last date/time </code></pre> <p>Your current setup just appears a bit messy &amp; cluttered and not very readable.</p> <p><strong>The Solution</strong></p> <p>To tidy it up a bit here's what I would do</p> <pre><code>public static class DateTimeExt { public static string ToRelativeTime(this DateTime value) { // you could move the entire implementation of `DisplayPostInMinutesOrSeconds` to here return IsPostLessThanOneHour.DisplayPostInMinutesOrSeconds(value); } } ... public PartialViewResult MostRecentMembersPosts() { return PartialView("pvMostRecentMembersPost", _imf.DisplayMostRecentForumPosts().ToList()); } </code></pre> <p>And then in your view</p> <pre><code>@model IEnumerable&lt;MemberForumProperties&gt; @foreach (var props in Model) { &lt;p&gt;@props.ForumMemberDateTimePostedPost.ToRelativeTime()&lt;/p&gt; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload