I have the following code:
<span>@Model.LicenseHolder.LegalPerson.ContactDetails.Select(x => x.Name == "Fish")</span>
When I run this, I get the error:
Operator '==' cannot be applied to operands 'method group' or 'string'
I don't understand why I get this.
Here you can see a picture of ContactDetails:
'
I want to access the ContactDataType property and compare the Name-property that Is Inside ContactDataType, but I don't know how do It. So basically, I want this: @Model.LicenseHolder.LegalPerson.ContactDetails.ContactDataType.Select(x => x.Name == "PrimaryPhone")
You need to apply it to your Where not Select function:
<span>@Model.LicenseHolder.LegalPerson.ContactDetails.Where(x => x.Name == "Fish").FirstOrDefault()</span>
Or even better:
<span>@Model.LicenseHolder.LegalPerson.ContactDetails.FirstOrDefault(x => x.Name == "Fish")</span>
The problem is, that you try to access the Name member which is probably a method and not a property.
On your screenshot we can see all available properties: ContactDataType, DebuggerDisplay, Detail, Id and PersonId. There is no Name. If it is a property you must add () to Name to execute it:
@Model.LicenseHolder.LegalPerson.ContactDetails.Select(x => x.Name() == "Fish")
This will return a IEnumerable<Boolean> but probably you want something else.
Maybe this?
@Model.LicenseHolder.LegalPerson.ContactDetails
.FirstOrDefault(x => x.Name() == "Fish")
.ContactDataType
This will return the first ContactDetails ContactDataType which Name() equals "Fish".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With