Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8137355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:05:26+00:00 2026-06-06T11:05:26+00:00

I had a similar question before, but this is a few steps beyond that

  • 0

I had a similar question before, but this is a few steps beyond that so here we go:

I am trying to access values in a category in Tridion 2011. I am using the Razor TBB and using this code to do it:

@foreach (var keyword in Publication.MetaData.myCategory) {
  @: Hello World!
}

I have set up a metadata schema with a field that has an xml name of “myCategory” attached to my publication. If I run this on the publication where myCategory is a Text field, this code works… kind of. It treats EACH character as a separate value of the keyword variable… so if I enter the text “one”, what prints is “Hello World! Hello World! Hello World!”, and if I just have “o” as the value, it prints “Hello World!”.

Bizarre as that is (and I’d like to know why on that too), what I really want the field to be a “Values will be selected from a list” type of field, pointing to my category in Categories and keywords. When I do this, and the value of myCategory changes to the value of the item selected in the dropdown for this type of field instead of direct text entry, the code no longer works and gives this error:

Cannot implicitly convert type ‘Tridion.Extensions.Mediators.Razor.Models.KeywordModel’ to ‘System.Collections.IEnumerable’. An explicit conversion exists (are you missing a cast?)

Please help me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T11:05:29+00:00Added an answer on June 6, 2026 at 11:05 am

    If you get your output repeated for every character in a string, you are clearly iterating over the characters in the string and not the other range of values that you expected.

    I quickly checked the relevant code of the Razor mediator and its ToString method indeed returns the Title of the underlying RepositoryLocalObject.

    http://code.google.com/p/razor-mediator-4-tridion/source/browse/trunk/Tridion.Extensions.Mediators.RazorMediator/Tridion.Extensions.Mediators.RazorMediator/Models/AbstractRepositoryLocalObject.cs

    http://code.google.com/p/razor-mediator-4-tridion/source/browse/trunk/Tridion.Extensions.Mediators.RazorMediator/Tridion.Extensions.Mediators.RazorMediator/Models/KeywordModel.cs

    http://code.google.com/p/razor-mediator-4-tridion/source/browse/trunk/Tridion.Extensions.Mediators.RazorMediator/Tridion.Extensions.Mediators.RazorMediator/Models/DynamicItemFields.cs

    The code that handles KeywordFields in in the DynamicItemsFields.cs file:

    else if (itemField is KeywordField)
    {
        KeywordField keywordField = (KeywordField)itemField;
        if (keywordField.Definition.MaxOccurs == 1)
            if (keywordField.Value == null)
                _dictionary[key] = null;
            else
                _dictionary[key] = new KeywordModel(_engine, keywordField.Value);
        else
        {
            List<KeywordModel> keywords = new List<KeywordModel>();
            int i = 0;
            foreach (Keyword k in keywordField.Values)
            {
                var kw = new KeywordModel(_engine, k);
                kw.Index = i++;
                kw.IsLast = Index == keywordField.Values.Count - 1;
                keywords.Add(kw);
            }
            _dictionary[key] = keywords;
        }
    }
    

    So it looks like the myCategory property will either be a KeywordModel object (if the KeywordField is single-value) or a List<KeywordModel> (if the KeywordField is marked as multi-value in the Schema). Is your myCategory field single value? Or multi-value?

    If it is single-value, what type of output were your expecting? If you were expecting the list of allowed values (instead of the currently selected value), check if you can access it through myCategory.Definition somehow (which should be a regular TOM.NET KeywordFieldDefinition object).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ive had a similar question as this one before, and when that solved this
I had asked a question similar to this before, but I have a new
Various incarnations of this question have been asked here before, but I thought I'd
I know similar question was answered a lot times before, but I hope this
OK, I had asked a similar question before and had got an answer but
I've asked a similar question before, but I've done some more research and this
I had asked the similar question before , understood that i can make it
I had a similar question a while back, but with much less of a
I had asked a question very much similar to this in the thread: https://stackoverflow.com/questions/11259474/store-the-numericals-in-char-array-into-an-integer-variable-in-vc
I've had a look at other questions similar to this one but I couldn't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.