2014-08-30 3 views

답변

5

이게 뭔가.

당신은 참조 할 필요가 :

@using umbraco.cms.businesslogic.datatype 

다음에서 데이터 유형 ID를 가져 :) (

var dataTypeId = umbraco.cms.businesslogic.datatype.DataTypeDefinition 
       .GetAll().First(d=> d.Text == "DataTypeName").Id; 

var preValues = PreValues.GetPreValues(dataTypeId).Values; 
var enumerator = preValues.GetEnumerator(); 
while (enumerator.MoveNext()) 
{ 
    var preValueText = ((PreValue)enumerator.Current).Value; 
    <option>@preValueText</option> 
} 
3

당신은 Umbraco 도우미에

Umbraco.DataTypeService.GetPreValuesByDataTypeId을 DataTypeService을 사용할 수 있습니다

0
@foreach (var categoryPrevalue in ApplicationContext.Services.DataTypeService.GetPreValuesByDataTypeId(**-42**).ToList()) 

     { 
     <li><a href="#">@categoryPrevalue</a></li> 
     } 

"-42"은 Umbraco 백 오피스의 Datatypeid로 변경해야합니다.

2

Umbraco 7.x에서 umbraco.cms.businesslogic.datatype.DataTypeDefinition은 더 이상 사용되지 않습니다.

대신 다음을 사용했습니다. @ Kerpalito의 답변에 감사드립니다.하지만 환경 사이에서 바뀔 수 있으므로 데이터 유형의 ID를 하드 코딩하고 싶지 않았습니다. 이름은 모든 환경에서 동일합니다.

public List<string> GetPrevalues() 
{ 
     List<string> toReturn = new List<string>(); 

     IDataTypeDefinition dataType = ApplicationContext.Current.Services.DataTypeService.GetDataTypeDefinitionByName("My Data Type Name"); 

     if (dataType == null) 
     { 
      return toReturn; 
     } 

     PreValueCollection preValues = ApplicationContext.Current.Services.DataTypeService.GetPreValuesCollectionByDataTypeId(dataType.Id); 

     if (preValues == null) 
     { 
      return toReturn; 
     } 

     IDictionary<string, PreValue> tempDictionary = preValues.FormatAsDictionary(); 

     toReturn = tempDictionary.Select(p => p.Value.Value).ToList(); 

     return toReturn; 
} 
관련 문제