# Get option values from TextOption field

**URL:** <https://forum.litium.com/t/get-option-values-from-textoption-field/2066>\
**Category:** Questions\
**Created:** [May 21, 2021, 1:40pm UTC](https://forum.litium.com/t/get-option-values-from-textoption-field/2066 "2021-05-21T13:40:39Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![anek](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@anek](https://forum.litium.com/u/anek)\
**Post date:** [May 21, 2021, 1:40pm UTC](https://forum.litium.com/t/get-option-values-from-textoption-field/2066/1 "2021-05-21T13:40:40Z")

</div>

I’m trying to get the values from TextOption but it just returns null.  
I’ve set it up in AcceleratorWebsiteFieldDefinitionSetup and added some options to it.

When i’m trying to get the values in my ViewModelBuild with `website.Fields.GetValue<IList<string>>(PageFieldNameConstants.MyTextOptionField, CultureInfo.CurrentUICulture);` it just returns null.

(website is `_requestModelAccessor.RequestModel.WebsiteModel`)

Litium version: 7

---

<div class="post-metadata">

**Author:** ![NilsN](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/nilsn/32/302_2.png) [@NilsN](https://forum.litium.com/u/NilsN)\
**Post date:** [May 21, 2021, 1:54pm UTC](https://forum.litium.com/t/get-option-values-from-textoption-field/2066/2 "2021-05-21T13:54:37Z")

</div>

Is the field multi-culture? Otherwise, you should omit `CultureInfo.CurrentUICulture`.

You can also use the `WebsiteModel` directly, like  
`websiteModel.GetValue<IList<string>>(PageFieldNameConstants.MyTextOptionField)` and it will check with and without culture automatically.

---

<div class="post-metadata">

**Author:** ![anek](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@anek](https://forum.litium.com/u/anek)\
**Post date:** [May 21, 2021, 2:01pm UTC](https://forum.litium.com/t/get-option-values-from-textoption-field/2066/3 "2021-05-21T14:01:57Z")

</div>

Yeah it is.

So something like this?  
`MyViewModel Build(WebsiteModel websiteModel) { model.MyStringList = websiteModel.GetValue<IList<string>>PageFieldNameConstants.MyTextOptionField) }`

---

<div class="post-metadata">

**Author:** ![NilsN](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/nilsn/32/302_2.png) [@NilsN](https://forum.litium.com/u/NilsN)\
**Post date:** [May 21, 2021, 2:06pm UTC](https://forum.litium.com/t/get-option-values-from-textoption-field/2066/4 "2021-05-21T14:06:52Z")

</div>

Yes, just missing a `(` before the constant.

But if the field is set to multi culture, have you double-checked that there is a value for the language you want?

---

<div class="post-metadata">

**Author:** ![anek](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@anek](https://forum.litium.com/u/anek)\
**Post date:** [May 21, 2021, 2:11pm UTC](https://forum.litium.com/t/get-option-values-from-textoption-field/2066/5 "2021-05-21T14:11:19Z")

</div>

Yeah there’s a value for every language i have. In the pages that uses a selected value it works.  
But not here when i want to get all the values

---

<div class="post-metadata">

**Author:** ![NilsN](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/nilsn/32/302_2.png) [@NilsN](https://forum.litium.com/u/NilsN)\
**Post date:** [May 21, 2021, 2:27pm UTC](https://forum.litium.com/t/get-option-values-from-textoption-field/2066/6 "2021-05-21T14:27:01Z")

</div>

Do you want to get all the possible values for the field?  
And not the selected values for the field on the current website?

If so, then you should get the definition of the field instead. Something like:

```auto
var field = _fieldDefinitionService.Get<WebsiteArea>(PageFieldNameConstants.MyTextOptionField);
var options = field.Option as TextOption;
var values = options.Items.Select(option => option.Value);

```

---

<div class="post-metadata">

**Author:** ![anek](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@anek](https://forum.litium.com/u/anek)\
**Post date:** [May 21, 2021, 2:35pm UTC](https://forum.litium.com/t/get-option-values-from-textoption-field/2066/7 "2021-05-21T14:35:02Z")

</div>

Ah perfect, that was exactly what i needed!  
Thank you and have a great weekend 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/litium/original/1X/12eddac3b8b661de1db86af10ac8151b571e6fb9.png) [@system](https://forum.litium.com/u/system)\
**Post date:** [June 18, 2021, 2:35pm UTC](https://forum.litium.com/t/get-option-values-from-textoption-field/2066/8 "2021-06-18T14:35:24Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
