Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ You can use dictionary items to translate the options in a Checkbox List propert

## MVC View Example

### Without Modelsbuilder
### Without Models Builder

```csharp
@{
Expand All @@ -42,7 +42,7 @@ You can use dictionary items to translate the options in a Checkbox List propert
}
```

### With Modelsbuilder
### With Models Builder

```csharp
@{
Expand All @@ -67,25 +67,22 @@ The example below demonstrates how to add values programmatically using a Razor
{% endhint %}

```csharp
@inject IContentService Services;
@using Umbraco.Cms.Core.Serialization
@using Umbraco.Cms.Core.Services;
@inject IJsonSerializer Serializer;
@using Umbraco.Cms.Core.Services
@inject IContentService ContentService
@inject IJsonSerializer Serializer
@{
// Get access to ContentService
var contentService = Services;

// Create a variable for the GUID of the page you want to update
var guid = Guid.Parse("32e60db4-1283-4caa-9645-f2153f9888ef");

// Get the page using the GUID you've defined
var content = contentService.GetById(guid); // ID of your page
var content = ContentService.GetById(guid); // ID of your page

// Set the value of the property with alias 'superHeros'.
content.SetValue("superHeros", Serializer.Serialize(new[] { "Umbraco", "CodeGarden"}));
// Set the value of the property with alias 'superHeroes'.
content.SetValue("superHeroes", Serializer.Serialize(new[] { "Umbraco", "CodeGarden"}));

// Save the change
contentService.Save(content);
ContentService.Save(content);
}
```

Expand All @@ -94,20 +91,17 @@ Although the use of a GUID is preferable, you can also use the numeric ID to get
```csharp
@{
// Get the page using it's id
var content = contentService.GetById(1234);
var content = ContentService.GetById(1234);
}
```

If Modelsbuilder is enabled you can get the alias of the desired property without using a magic string:

{% include "../../../../.gitbook/includes/obsolete-warning-ipublishedsnapshotaccessor.md" %}
If Models Builder is enabled you can get the alias of the desired property without using a magic string:

```csharp
@inject IPublishedSnapshotAccessor _publishedSnapshotAccessor;
@using Umbraco.Cms.Core.PublishedCache;
@using Umbraco.Cms.Core.PublishedCache
@inject IPublishedContentTypeCache PublishedContentTypeCache
@{

// Set the value of the property with alias 'superHeros'
content.SetValue(Home.GetModelPropertyType(_publishedSnapshotAccessor,x => x.SuperHeros).Alias, Serializer.Serialize(new[] { "Umbraco", "CodeGarden"}));
// Set the value of the property with alias 'superHeroes'
content.SetValue(Home.GetModelPropertyType(PublishedContentTypeCache, x => x.SuperHeroes).Alias, Serializer.Serialize(new[] { "Umbraco", "CodeGarden"}));
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ It is possible to add a label to use with the color.

![Color Picker Content](../../../../../../10/umbraco-cms/fundamentals/backoffice/property-editors/built-in-property-editors/images/Color-Picker-Content-v8.png)

## Example with Modelsbuilder
## Example with Models Builder

```csharp
@{
Expand All @@ -36,7 +36,7 @@ It is possible to add a label to use with the color.
}
```

## Example without Modelsbuilder
## Example without Models Builder

```csharp
@using Umbraco.Cms.Core.PropertyEditors.ValueConverters
Expand Down Expand Up @@ -64,48 +64,42 @@ The example below demonstrates how to add values programmatically using a Razor
### Without labels

```csharp
@inject IContentService Services;
@using Umbraco.Cms.Core.Services;
@using Umbraco.Cms.Core.Services
@inject IContentService ContentService
@{
// Get access to ContentService
var contentService = Services;

// Create a variable for the GUID of the page you want to update
var guid = Guid.Parse("32e60db4-1283-4caa-9645-f2153f9888ef");

// Get the page using the GUID you've defined
var content = contentService.GetById(guid); // ID of your page
var content = ContentService.GetById(guid); // ID of your page

// Set the value of the property with alias 'color'.
// The value set here, needs to be one of the colors on the Color Picker
content.SetValue("color", "38761d");

// Save the change
contentService.Save(content);
ContentService.Save(content);
}
```

### With labels

```csharp
@inject IContentService Services;
@using Umbraco.Cms.Core.Services;
@using Umbraco.Cms.Core.Services
@inject IContentService ContentService
@{
// Get access to ContentService
var contentService = Services;

// Create a variable for the GUID of the page you want to update
var guid = Guid.Parse("32e60db4-1283-4caa-9645-f2153f9888ef");

// Get the page using the GUID you've defined
var content = contentService.GetById(guid); // ID of your page
var content = ContentService.GetById(guid); // ID of your page

// Set the value of the property with alias 'color'.
// The value set here, needs to be one of the colors on the Color Picker
content.SetValue("color", "{'value':'000000', 'label':'Black', 'sortOrder':1, 'id':'1'}");

// Save the change
contentService.Save(content);
ContentService.Save(content);
}
```

Expand All @@ -114,19 +108,17 @@ Although the use of a GUID is preferable, you can also use the numeric ID to get
```csharp
@{
// Get the page using it's id
var content = contentService.GetById(1234);
var content = ContentService.GetById(1234);
}
```

If Modelsbuilder is enabled you can get the alias of the desired property without using a magic string:

{% include "../../../../.gitbook/includes/obsolete-warning-ipublishedsnapshotaccessor.md" %}
If Models Builder is enabled you can get the alias of the desired property without using a magic string:

```csharp
@inject IPublishedSnapshotAccessor _publishedSnapshotAccessor;
@using Umbraco.Cms.Core.PublishedCache;
@using Umbraco.Cms.Core.PublishedCache
@inject IPublishedContentTypeCache PublishedContentTypeCache
@{
// Set the value of the property with alias 'color'
content.SetValue(Home.GetModelPropertyType(_publishedSnapshotAccessor, x => x.Color).Alias, "38761d");
content.SetValue(Home.GetModelPropertyType(PublishedContentTypeCache, x => x.Color).Alias, "38761d");
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ When opening the picker on the `Umbraco anno MMXXIII` node, it will now show the

## MVC View Example

### Without Modelsbuilder
### Without Models Builder

```csharp
@{
Expand All @@ -213,7 +213,7 @@ When opening the picker on the `Umbraco anno MMXXIII` node, it will now show the
}
```

### With Modelsbuilder
### With Models Builder

```csharp
@{
Expand All @@ -234,19 +234,15 @@ The example below demonstrates how to add values programmatically using a Razor
{% endhint %}

```csharp
@inject IContentService Services;
@using Umbraco.Cms.Core;
@using Umbraco.Cms.Core
@using Umbraco.Cms.Core.Services

@inject IContentService ContentService
@{
// Get access to ContentService
var contentService = Services;

// Create a variable for the GUID of the page you want to update
var guid = Guid.Parse("32e60db4-1283-4caa-9645-f2153f9888ef");

// Get the page using the GUID you've defined
var content = contentService.GetById(guid); // ID of your page
var content = ContentService.GetById(guid); // ID of your page

// Get the pages you want to assign to the Content Picker
var page = Umbraco.Content("665d7368-e43e-4a83-b1d4-43853860dc45");
Expand All @@ -263,7 +259,7 @@ The example below demonstrates how to add values programmatically using a Razor
content.SetValue("featuredArticles", string.Join(",", udis));

// Save the change
contentService.Save(content);
ContentService.Save(content);
}
```

Expand All @@ -272,20 +268,17 @@ Although the use of a GUID is preferable, you can also use the numeric ID to get
```csharp
@{
// Get the page using it's id
var content = contentService.GetById(1234);
var content = ContentService.GetById(1234);
}
```

If Modelsbuilder is enabled you can get the alias of the desired property without using a magic string:

{% include "../../../../.gitbook/includes/obsolete-warning-ipublishedsnapshotaccessor.md" %}
If Models Builder is enabled you can get the alias of the desired property without using a magic string:

```csharp
@inject IPublishedSnapshotAccessor _publishedSnapshotAccessor;
@using Umbraco.Cms.Core.PublishedCache;

@using Umbraco.Cms.Core.PublishedCache
@inject IPublishedContentTypeCache PublishedContentTypeCache
@{
// Set the value of the property with alias 'featuredArticles'
content.SetValue(Home.GetModelPropertyType(_publishedSnapshotAccessor ,x => x.FeaturedArticles).Alias, string.Join(",", udis));
content.SetValue(Home.GetModelPropertyType(PublishedContentTypeCache, x => x.FeaturedArticles).Alias, string.Join(",", udis));
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ The setting involves defining the format. The default date format in the Umbraco

## MVC View Example - displays a datetime

### With Modelsbuilder
### With Models Builder

```csharp
@Model.DatePicker
```

### Without Modelsbuilder
### Without Models Builder

```csharp
@Model.Value("datePicker")
Expand All @@ -43,23 +43,20 @@ The example below demonstrates how to add values programmatically using a Razor
{% endhint %}

```csharp
@inject IContentService Services;
@using Umbraco.Cms.Core.Services;
@using Umbraco.Cms.Core.Services
@inject IContentService ContentService
@{
// Get access to ContentService
var contentService = Services;

// Create a variable for the GUID of the page you want to update
var guid = new Guid("32e60db4-1283-4caa-9645-f2153f9888ef");

// Get the page using the GUID you've defined
var content = contentService.GetById(guid); // ID of your page
var content = ContentService.GetById(guid); // ID of your page

// Set the value of the property with alias 'datePicker'
content.SetValue("datePicker", DateTime.Now);

// Save the change
contentService.Save(content);
ContentService.Save(content);
}
```

Expand All @@ -68,20 +65,18 @@ Although the use of a GUID is preferable, you can also use the numeric ID to get
```csharp
@{
// Get the page using it's id
var content = contentService.GetById(1234);
var content = ContentService.GetById(1234);
}
```

If Modelsbuilder is enabled you can get the alias of the desired property without using a magic string:

{% include "../../../../.gitbook/includes/obsolete-warning-ipublishedsnapshotaccessor.md" %}
If Models Builder is enabled you can get the alias of the desired property without using a magic string:

```csharp
@using Umbraco.Cms.Core.PublishedCache;
@inject IPublishedSnapshotAccessor _publishedSnapshotAccessor;
@using Umbraco.Cms.Core.PublishedCache
@inject IPublishedContentTypeCache PublishedContentTypeCache
@{

// Set the value of the property with alias 'datePicker'
content.SetValue(Home.GetModelPropertyType(_publishedSnapshotAccessor, x => x.DatePicker).Alias, DateTime.Now);
content.SetValue(Home.GetModelPropertyType(PublishedContentTypeCache, x => x.DatePicker).Alias, DateTime.Now);
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ If the value of **Step Size** is not set then all decimal values between 8 and 1

## MVC View Example

### With Modelsbuilder
### With Models Builder

```csharp
@Model.MyDecimal
```

### Without Modelsbuilder
### Without Models Builder

```csharp
@Model.Value("MyDecimal")
Expand All @@ -43,23 +43,20 @@ The example below demonstrates how to add values programmatically using a Razor
{% endhint %}

```csharp
@inject IContentService Services;
@using Umbraco.Cms.Core.Services;
@using Umbraco.Cms.Core.Services
@inject IContentService ContentService
@{
// Get access to ContentService
var contentService = Services;

// Create a variable for the GUID of the page you want to update
var guid = Guid.Parse("32e60db4-1283-4caa-9645-f2153f9888ef");

// Get the page using the GUID you've defined
var content = contentService.GetById(guid); // ID of your page
var content = ContentService.GetById(guid); // ID of your page

// Set the value of the property with alias 'myDecimal'.
content.SetValue("myDecimal", 3);

// Save the change
contentService.Save(content);
ContentService.Save(content);
}
```

Expand All @@ -68,19 +65,17 @@ Although the use of a GUID is preferable, you can also use the numeric ID to get
```csharp
@{
// Get the page using it's id
var content = contentService.GetById(1234);
var content = ContentService.GetById(1234);
}
```

If Modelsbuilder is enabled you can get the alias of the desired property without using a magic string:

{% include "../../../../.gitbook/includes/obsolete-warning-ipublishedsnapshotaccessor.md" %}
If Models Builder is enabled you can get the alias of the desired property without using a magic string:

```csharp
@inject IPublishedSnapshotAccessor _publishedSnapshotAccessor;
@using Umbraco.Cms.Core.PublishedCache;
@using Umbraco.Cms.Core.PublishedCache
@inject IPublishedContentTypeCache PublishedContentTypeCache
@{
// Set the value of the property with alias 'myDecimal'
content.SetValue(Home.GetModelPropertyType(_publishedSnapshotAccessor, x => x.MyDecimal).Alias, 3);
content.SetValue(Home.GetModelPropertyType(PublishedContentTypeCache, x => x.MyDecimal).Alias, 3);
}
```
Loading