Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hey! I need to get the prevalues of a Data Type on my hompage. I´m using Umbraco 8. This is my master-head:
@inherits Umbraco.Web.Mvc.UmbracoViewPage @{ Layout = null; }
and this is my homepage-head:
@inherits Umbraco.Web.Mvc.UmbracoViewPage<ContentModels.Homepage> @using ContentModels = Umbraco.Web.PublishedModels; @{ Layout = "master.cshtml"; }
When I use
@foreach (var categoryPrevalue in ApplicationContext.Services.DataTypeService.GetPreValuesByDataTypeId(1125).ToList()) { <li>@categoryPrevalue</li> }
I get the error:
CS0103: The name 'ApplicationContext' does not exist in the current context
What can I do?! Thanks and best regards, Christoph
Try using
Current.Services.
to find the relevant service.
Kind regards
Paul
If I try this in a partial view it says "The name 'Current' does not exist in the current context."
I was able to get to the DataTypeService by using Services.DataTypeService in Umbraco 8.4.1
Services.DataTypeService
Hi, we created the following, to return the prevalues as a list:
public static List<PreValue> GetDataTypePreValues(int id) { IDataTypeService dataTypeService = Current.Services.DataTypeService; List<PreValue> toReturn = new List<PreValue>(); IDataType dataType = dataTypeService.GetDataType(id); if (dataType != null) { ValueListConfiguration valueList = (ValueListConfiguration)dataType.Configuration; if (valueList != null && valueList.Items != null && valueList.Items.Any()) { toReturn.AddRange(valueList.Items.Select(s => new PreValue { Id = s.Id, Value = s.Value })); } } return toReturn; }
using the following class:
public class PreValue { public int Id { get; set; } public string Value { get; set; } }
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
Datatype prevalues in Umbraco 8
Hey! I need to get the prevalues of a Data Type on my hompage. I´m using Umbraco 8. This is my master-head:
and this is my homepage-head:
When I use
I get the error:
What can I do?! Thanks and best regards, Christoph
Try using
to find the relevant service.
Kind regards
Paul
If I try this in a partial view it says "The name 'Current' does not exist in the current context."
I was able to get to the DataTypeService by using
Services.DataTypeService
in Umbraco 8.4.1Hi, we created the following, to return the prevalues as a list:
using the following class:
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.