Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Convert object to list dictionary

$
0
0

Hey everyone,

I'm creating a function to create my breadcrumbs out of a list that is placed in my datatoken from the route. I got the list out of the datatoken as a object but how do I convert it back to that list with dictionaries?

With this I made the list with dictionary

public class ParentUrlParents
{
    public List<Dictionary<string, object>> List = new List<Dictionary<string, object>>();
}

public static Dictionary<string, object> ChildUrlParents;

I tried things like this to convert it back

object ObjectBreadcrumbs = RouteData.DataTokens.FirstOrDefault(x => x.Key == "ParentUrlParents").Value;
//ParentBreadcrumbs ParentBreadcrumbs;

var s = ((Dictionary<string, object>)ObjectBreadcrumbs).ToList();

var t = (List<Dictionary<string, object>>)ObjectBreadcrumbs;

But then I got this error:

Unable to cast object of type 'ParentUrlParents' to type 'System.Collections.Generic.Dictionary`2[System.String,System.Object]'.


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>