You are very close with your approach that you are trying to be fair.
What you need to do is explicitly tell GetPropertyValue what type it should be returning, but there is a catch to this because it can cause Razor to jump out of the c# code and into the HTML code.
Your first string works nicely. I had some issues wrapping it in an @if statement, but I got this to work.
@{
if (Model.Content.HasValue("mondayFrom") && Model.Content.HasValue("mondayTo"))
{
var fra = Model.Content.GetPropertyValue<DateTime>("mondayFrom").ToString("HH.mm");
var til = Model.Content.GetPropertyValue<DateTime>("mondayTo").ToString("HH.mm");
<li>Mandag @fra - @til</li>
}
}
How to format time without @CurrentPage ?
On my website I want to display office hours as e.g. 08.30 - 16.00.
I can achieve this using
However, to my understanding @CurrentPage is faux pas, and I would rather use something like
I tried adding the ToString("HH.mm") without much success. Is there a better way to do this?
Hi Jesper,
You are very close with your approach that you are trying to be fair.
What you need to do is explicitly tell
GetPropertyValue
what type it should be returning, but there is a catch to this because it can cause Razor to jump out of the c# code and into the HTML code.So what you can do is this:
Another option is this (I'm writing this on from memory so it might have a syntax error in it):
Nik
Hi Nik
The devil is in the detail :-)
Your first string works nicely. I had some issues wrapping it in an @if statement, but I got this to work.
is working on a reply...