I am developing MVC application and using razor syntax.
In this application I am giving comment facility.
Currently the comments look like…
P Moris9/15/2012 5:40:44 PM
Test comment 1
P Moris9/15/2012 5:40:44 PM
Test comment 2
P moris9/15/2012 5:40:45 PM
Test comment 3
Now, I wan to put space between Name of the comment owner and the datetime.
As well How do I convert dateTime in to
dd-MMM-yy hh:mm tt ?
The Comment should be look like …
P Moris 17 Sept 2012 05:45 PM.
Test comment 1
(I cant give more than one space in above sample…its automatically remove the space.)
How should I ?
My code in View is
@foreach (var item in Model)
{
<div id="OwnerName">
<span class="EmpName"> @Html.ActionLink(item.Owner.FullName, "Details", "EMployee", new { id = item.OwnerId }, new { @style = "color:#1A6690;" })</span>
@Html.DisplayFor(ModelItem => item.CommentDateTime)
</div>
<p class="CommentP">
@Html.DisplayFor(ModelItem => item.CommentText)
</p>
<br />
}
You could put an
between the comment author name and the creation date:And in order to format the comment date you could decorate your view model property with the
[DisplayFormat]attribute:And if for some reason you are not using view models and cannot modify your entities you could format it in the view:
Another possibility is to write a custom display template (
~/Views/Shared/DisplayTemplates/CommentDate.cshtml):and then pass the custom display template name to the
DisplayForhelper: