I get this error: System.ArgumentNullException: Value cannot be null. But that is the point right? if .FreeAmount is null it should check in the AmountList for a Selected amount. However it fails doing so. I can't really see what I have done wrong here.
var amount = string.IsNullOrEmpty(formModel.FreeAmount)
? formModel.AmountList
.Where(x => x.Selected)
.Select(a => a.Value)
.SingleOrDefault()
: formModel.FreeAmount;
formModel's class as welll asAmountList's class.fromModelwas null then you would getNullReferenceException, notArgumentNullException.formModel.AmountList.Where(x => x.Selected).DefaultIfEmpty(0).Select(a => a.Value).SingleOrDefault()