0

I am trying to display the values of an icollection in cshtml nut instead of the value I get the system reference. System.Data.Entity.DynamicProxies.ReferralICD10Code_F7D1453817B346998A38AA8F0A6458AB31F1C8E815585BE8E92F6BBA57298BC8

The icollection is defined as

[Display(Name = "Referral ICD10Codes")]
public virtual ICollection<ReferralICD10Code> ReferralICD10Codes { get; set; }

And when I try to build up the variable to display in the cshtml I am using

    @{ 
        var reficd10codes = "";
        foreach (var item in Model.Visit.ReferralICD10Codes)
        {
            reficd10codes = reficd10codes + " " + Model.Visit.ReferralICD10Codes.FirstOrDefault().ToString();
        }
    }

If I leave out the firstordefault() I get

System.Collections.Generic.HashSet`1[Clinton.Core.Domain.ReferralICD10Code]

So now I am trying to figure out how to get the actual values instead of the reference.

Thanks

Dai
  • 141,631
  • 28
  • 261
  • 374
Marc L
  • 837
  • 9
  • 19
  • 40
  • Don't use EF Entity types for two-way models in ASP.NET / ASP.NET Core. You need to define a separate DTO/Form-Item `class`. – Dai Sep 22 '22 at 14:54
  • `reficd10codes = reficd10codes + " "` - **ew** - [don't use `+` for repetitive concatenation](https://stackoverflow.com/questions/21078/most-efficient-way-to-concatenate-strings) – Dai Sep 22 '22 at 14:55
  • What does `class ReferralICD10Code` look like? – Dai Sep 22 '22 at 14:56
  • `Model.Visit.ReferralICD10Codes.FirstOrDefault().ToString()` <-- **This does not do what you think it does** (and you never use `item` in your `foreach` loop, so there's at least 3 things very wrong with your code as-is). – Dai Sep 22 '22 at 14:57
  • Which is why I tried it without the FirstOrDefualt when I realised it was wrong. But still don't get the value without it. – Marc L Sep 22 '22 at 15:04
  • Your `item` is a `ReferralICD10Code` **object** (a structured area of memory: a `class` instance), not a `String` value. I assume that you _do_ know why you can't concatenate a .NET/CLR GC object to a `String`... – Dai Sep 22 '22 at 15:06

0 Answers0