Developer forum

Forum » Dynamicweb 9.0 Upgrade issues » Model.Item.GetString(

Model.Item.GetString(

Simon Nordahl
Simon Nordahl
Reply

Hi all

We just upgraded from 9.3 to 9.4.14.

After (no problem before) the upgrade our templates now throws an exception due to the following line: ,

@Model.Item.GetString("Title")

First I thought it was due to me inserting a null into the template so i tried the following:

var title = Model.Item.GetString("Title") ?? string.Empty;

@title

But that still did not fix the issue.

When expection the decompiled code its clear that it is done on purpose:

    public ItemFieldViewModel GetField(string systemName)
    {
      ItemFieldViewModel itemFieldViewModel = this.Fields.FirstOrDefault<ItemFieldViewModel>((Func<ItemFieldViewModel, bool>) (f => string.Equals(f.SystemName, systemName, StringComparison.OrdinalIgnoreCase)));
      if (itemFieldViewModel != null)
        return itemFieldViewModel;
      throw new Exception(string.Format("A field with the name {0} does not exist", (object) systemName));
    }

Right now I'm left with a clumpsy extensive workaround:

    var hasTitle = Model.Item.Fields.Any(s=> s.SystemName.Equals("Title", StringComparison.InvariantCultureIgnoreCase));
    var title = hasTitle ? Model.Item.GetString("Title") : string.Empty;

     @title

 

My question is WHY? It have always been that you could do a get string and worst case would be that you get an empty string.

Regards

Simon Nordahl

 


Replies

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Simon

It seems to be a feature request from partners who did not understand why there GetXX("") calls did not return anything - because they used wrong names and got no information that was the case... But I agree that this is even more anoying...

Reverted the change in TFS#54171 due with the next 9.4 and 9.5 hotfixes.

BR Nicolai

Votes for this answer: 1

 

You must be logged in to post in the forum