简体   繁体   中英

Getting list of properties of a DataType from current page

Good evening!

I am currently working on the backend of my application and I need to get a list of all properties of a certain datatype but only the ones in the current page.

listFiltersCms = _umbraco.ContentAtRoot().SelectMany(c => c.Descendants<DataFilters>()).ToList();

This line above gathers all the filters from all the pages, but I want the filters from a specific page (can be currentPage).

I have tried something like this:

var listFiltersCms = _umbraco.AssignedContentItem.SelectMany(c => c.Descendants<DataFilter>()).ToList();

But without any luck:( Any ideas?

Not entirely sure what you mean by "the backend of my application" - are you inside Umbraco or on a public website?

I ask because there is a fairly straightforward way of getting all info on a specific datatype, but it is not really meant to be used on public facing websites. It can be, but it might be taxing on the system as I believe it queries the database directly, which is not ideal.

Anyway, you might want to take a look at the DataTypeService: https://our.umbraco.com/Documentation/Reference/Management/Services/DataTypeService/Index-v8

And here you can see what options you have for using it (not very explanatory, but I spot a few methods you could probably look into): https://our.umbraco.com/apidocs/v8/csharp/api/Umbraco.Core.Services.IDataTypeService.html

If you decide to use the service in a scenario where there will be a lot of requests, maybe consider caching the output to spare the database.

The way I solved this issue was by getting the page in the correct model. In my case all I had to do was: (_umbraco.AssignedContentItem as PageModel).FilterCustomMeasures;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM