Guys,
I am using the awesome datatype grid in ucomponents. I have some text fields and media picker fields. The media picker fields are not mandatory and therefore will not always have a value in my code i have the following:
var answers=new List<Answer>();
var lib = new umbraco.MacroEngines.Library.RazorLibraryCore(questionNode);
var answerXml = lib.ToDynamicXml(questionNode.GetProperty<string>(DocumentType.Questions.Question.Answers));
foreach (var answer in answerXml)
{
var answerPoco = new Answer
{
QuestionId = questionNode.Id,
Text = answer.answer.InnerText,
Weight = int.Parse(answer.weight.InnerText),
PercentageAnswered = answer.percentageAnswered.InnerText
};
//todo cyan / pink
//DIES HERE HOW DO I TEST IT EXISTS
if (answer.answerCyan != null && !string.IsNullOrEmpty(answer.answerCyan.ToString()))
{
answerPoco.CyanImg = answer.answerCyan.InnerText;
}
if (answer.answerPink != null && !string.IsNullOrEmpty(answer.answerPink.ToString()))
{
answerPoco.PinkImg = answer.answerPink.InnerText;
}
answers.Add(answerPoco);
}
I need to test that the property exists before trying to reference it. So answercyan and answerping are media pickers in the datatype grid datatype and will not always have a value.
Datatypegrid null test
Guys, I am using the awesome datatype grid in ucomponents. I have some text fields and media picker fields. The media picker fields are not mandatory and therefore will not always have a value in my code i have the following:
I need to test that the property exists before trying to reference it. So answercyan and answerping are media pickers in the datatype grid datatype and will not always have a value.
Regards
Ismail
Hey Ismail I may be wrong, but are you looking to compare your dynamic property versus a DynamicNull?
Jamie
Jamie,
Weird its working now. So even if no value selected i will always have a blank node in the xml for the property so i just have to do
answer.answerPink.InnerText!=string.empty
No idea why maybe xml cache refresh or something but that works. Your answer if useful will keep in mind for similar in future.
Regards
Ismail
No problem, mate!
is working on a reply...