Closed wiedikerli closed 7 years ago
@ninjaonsafari Do you perhaps have an example of your code?
I just copied the code from the example.
var opening = Model.Content.GetOpeningHours();
@ninjaonsafari When using that extension method without any parameters, the method assumes the alias of your property is openingHours
. If this doesn't match your document type, you can specify the alias explicitly instead - eg. Model.Content.GetOpeningHours("shopOpeningHours")
.
@abjerner i now have this code:
var asdf = Model.Content.GetPropertyValue<OpeningHoursModel>("openingHours");
var opening = Model.Content.GetOpeningHours("openingHours");
but it still doesnt return anything.
@ninjaonsafari what does it say if you try something like:
var property = Model.Content.GetProperty("openingHours");
if (property == null) {
<pre>Property no found</pre>
} else {
<pre>@property.PropertyTypeAlias => @property.DataValue</pre>
}
This should write out the raw JSON.
I see the values in the raw JSON. So maybe there is something wrong in the ValueConverter?
openingHours => {
"weekdays": {
"0": {
"label": "Sunday",
"items": []
},
"1": {
"label": "Monday",
"items": [
{
"opens": "09:00",
"closes": "18:30"
}
]
},
"2": {
"label": "Tuesday",
"items": [
{
"opens": "09:00",
"closes": "18:30"
}
]
},
"3": {
"label": "Wednesday",
"items": [
{
"opens": "09:00",
"closes": "18:30"
}
]
},
"4": {
"label": "Thursday",
"items": [
{
"opens": "09:00",
"closes": "20:00"
}
]
},
"5": {
"label": "Friday",
"items": [
{
"opens": "09:00",
"closes": "20:00"
}
]
},
"6": {
"label": "Saturday",
"items": [
{
"opens": "08:00",
"closes": "17:00"
}
]
}
},
"holidays": [
{
"label": "",
"date": "",
"items": []
}
]
}
@ninjaonsafari Ok. I will do some testing with the JSON ;)
@ninjaonsafari At the end of the JSON, you have an empty holiday. So the internal parsing will fail (silently) because the empty string can't be parsed to a valid date.
So the simple answer is that fails because the entered data is invalid. But this might not be the best result when looking at user experience, so I'll see what I can to to improve the error handling ;)
I have pushed a new release where the date parsing has been changed a bit. Now, the invalid holiday item will simply be ignored instead of making the entire model fail ;)
If installed the project via nuget and filled up the property. But when I want to render it on the frontend the OpeningHoursTimeSlot object is empty.