❔ what the proper way to check if ``dynamic`` has a specific property?
I have this code below
now I'm passing this as a
@model
to a partial view
how do i properly check if modelObject
has a property named Count? I searched for solutions online and most require me to turn it into a Dictionary BUT I DONT WANT TO DO THAT!! casting it to dictionary is just....redundant and doesn't feel right, anyways, is there a proper way to do it?9 Replies
The whole point about
dynamic
is that you lose any and all type information and safetyyeah but the data i send to this specific partial view vary a lot
if i make a class/struct just for the model it would contain 50+ properties
Some googling recommends
sounds like a weird page
a dictionary does sound like a good use case then
oh boy Rider bugs out, it thinkgs
.GetType()
is a member of the dynamic object, alright ill try this out![](https://utfs.io/f/c2ac6939-8ee6-452f-a538-1ed3d1591fe8-1nq2cb.png)
Something like strategy pattern on the page might help too, depending on type of object youll render parts of razor differently
.GetType() is a member of the dynamic object
dynamically
I suppose
which probably yields another dynamic
Down side is probably lots of duplication on page, sounds like you're building some sort of control renderer?
alright so I went for this code which for some reason automatically checks for null, thanks btw
![](https://utfs.io/f/005ca2cb-da2b-4d47-9dfa-e8493979eaad-1nq2cb.png)
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.