7

Im trying to map Sitecore "Name Value List" field to NameValueCollection using below code which is not working.

[SitecoreType(AutoMap = true)]
public interface IManifest
{
    string Title { get; set; }

    string Description { get; set; }

    string Author { get; set; }

    [SitecoreField("ErrorMessages")]
    NameValueCollection ErrorMessages { get; set; }
}

all other field values are being mapped except for "ErrorMessages". Does it require additional code/configuration to achieve this?

2
  • There seems to be a data mapper for both NameValueCollection and Dictionary<,> types (and has been for a few years) which both uses HttpUtility.ParseQueryString() under the hood, so theoretically your code should work unless you are using a very old version. Have you tried using Dictionary<string, string> instead? Commented Apr 25, 2018 at 10:45
  • I'm using version 4.3 which is almost latest one. Dictionary<string, string> is not working as well..
    – nari447
    Commented Apr 26, 2018 at 6:55

1 Answer 1

4

I'm not sure if you can achieve this without any custom code.

But I did find a quick workaround here https://community.sitecore.net/general/f/11/t/3026 :

[SitecoreField(Name_Value_ListFieldName)]
public virtual string Name_Value_List_Raw  {get; set;}  

public NameValueCollection Name_Value_List  {get {return 
HttpUtility.ParseQueryString(Name_Value_List_Raw); }}   
1
  • Well..the problem was my item template with this field was not published properly.(completely my mistake).. I've already seen this question on community and tried this workaround which didn't work.. proper publish and this answer worked for me.. thank you Marek..
    – nari447
    Commented Apr 26, 2018 at 7:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.