-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
razor view does allow dynamic casting of property values using system.text.json #16233
Comments
Did you try |
@Piedone yes i did , same result . |
the object is there but cannot access dynamically properties using dot notation : @faq.ContentItemId |
How should this be approached with STJ, @MikeAlhayek @sebastienros? |
I would've expected |
@gvkries ForTutors is BagPart named 'ForTutors' with a collection of content items. |
Okay, I think this happens because OrchardCore/src/OrchardCore/OrchardCore.Abstractions/Json/Dynamic/JsonDynamicArray.cs Line 14 in 77fa6e0
|
@gvkries thanks for the fix. |
Hmm, I'll have a look... |
I think it's not a |
@gvkries I tried removing the .Content part with no luck : |
You can cast that Was all of this working before with NewtonSoft.Json? |
@gvkries yes it was working with newtonsoft. the issue is that even without .Content it cannot resolve using dot notation. |
We triaged this issue and set the milestone according to the priority we think is appropriate (see the docs on how we triage and prioritize issues). This indicates when the core team may start working on it. However, if you'd like to contribute, we'd warmly welcome you to do that anytime. See our guide on contributions here. |
In comparison to Newtonsoft JSON, the primary limitation when using dynamics is the lack of direct value comparison. For instance, a straightforward comparison like Regarding the usage of |
yes , you are right about the string comparison :
But what i am finding is that the previous api that did a 1-1 mapping of the json with api now does'nt exist : for instance in previous api you could get strongly typed access to fields (because subscriptionElement was a contentitem) as so :
Now you cannot have this api access , right ? you would have to use stj helpers like json.selectNode(.....) . . correct ? Please tell me i am wrong ... |
@gvkries would it make sence to add an extension method like jsonobject.ToContentItem() to convert to contentitem and then use the same api again ? |
Yes, I think that is missing and we should add support for it back. Not sure if an extension method is enough though, we may need to support this on the dynamic wrappers too. |
I've read through this again, and I think the issue might be due to a change in how you're accessing the content items from the bag part. If you get the Instead, you need to directly access the shapes by using the So, instead of using: @foreach(var subscriptionElement in Model.ContentItem.Content.SubscriptionElements.ContentItems) use: @foreach(var subscriptionElement in Model.Content.SubscriptionElements.ContentItems) This will give you a |
Here is an excellent description of the differences I was referring too: |
@gvkries thanks. the extension method also solves it too. |
Using the new system.text.json seems to not cast to dynamic in razor views , so you cannot access dynamically property values like previously .
See in below image when looping in a razor view over some content items i cannot extract dynamically the ContentItemId Property value like before. is there a way to cast to dynamic like before ?
The text was updated successfully, but these errors were encountered: