4

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?

  • 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? – Søren Kruse Apr 25 '18 at 10:45
  • I'm using version 4.3 which is almost latest one. Dictionary<string, string> is not working as well.. – nari447 Apr 26 '18 at 6:55
3

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); }}   
| improve this answer | |
  • 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 Apr 26 '18 at 7:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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