Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I have a partial view where the model is inherited from a ViewModel instead on IPublishedContent.
How then can I access Umbraco dictionary values in the partial?
If inheriting from IPublishedContent the I just do this obviously
@Umbraco.GetDictionaryValue("Registration Text", "Reg txt")
I'm unsure how to do this when not inheriting from IPublishedContent.
Hi Damion !
Do you have the option to simply add another "string" property onto the ViewModel ? Like another property called "RegistrationText" or maybe "DicRegistrationText" or similar? If so you should be able to get it easy on the Model object.
It's a common MVC strategy to try and get the calls like "Umbraco.GetDictionaryValue" into the Controllers so you keep the Views nice and clean MVC-wise with only simple types, usually this means you can jump into where the ViewModel is created and set this value there.
If you're not sure where this is done in the solution, try and search for whereever in the solution it says "new [NameOfViewModel]", hopefully that's only one place :)
Yes I tried that, I have a test string on the ViewModel and tried to set it as
model.testTxt = Umbraco.GetDictionaryValue("registration-agree-terms");
on the render form action, but again nothing is returned.
I thought using the Umbraco helper here would have taken care of it.
It's not one of these weird v8 things is it?
just noticed that if I place a breakpoint below the line where I try to set testTxt and hover over 'Umbraco', I see this:
'Umbraco.AssignedContentItem' threw an exception of type 'System.InvalidOperationException'
You can write your own DictionaryService to access it and registers as singleton.
// Registering IDictionaryService composer
[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
public class RegisterComposer : IUserComposer
public void Compose(Composition composition)
// Creating IDictionaryService Class
public interface IDictionaryService
string GetDictionaryValue(string key);
string GetDictionaryValue(string key, string altText);
public class DictionaryService : IDictionaryService
private readonly ICultureDictionaryFactory _cultureDictionaryFactory;
private ICultureDictionary _cultureDictionary;
T Ensure<T>(T o) where T : class => o ?? throw new InvalidOperationException("This UmbracoHelper instance has not been initialized.");
private ICultureDictionaryFactory CultureDictionaryFactory => Ensure(_cultureDictionaryFactory);
public ICultureDictionary CultureDictionary => _cultureDictionary
?? (_cultureDictionary = CultureDictionaryFactory.CreateDictionary());
public DictionaryService(ICultureDictionaryFactory cultureDictionary)
_cultureDictionaryFactory = cultureDictionary ?? throw new ArgumentNullException(nameof(cultureDictionary));
public string GetDictionaryValue(string key)
public string GetDictionaryValue(string key, string altText)
var dictionaryValue = GetDictionaryValue(key);
dictionaryValue = altText;
In your Partial View, now you can do to get the value based on culture:-
@using Current = Umbraco.Web.Composing.Current;
IDictionaryService DictionaryService = Current.Factory.GetInstance<IDictionaryService>();
Nice Shaishav, I'll give that a try
Although it was good to be able to debug through the code in the service it still returned nothing. Not sure where to go with this now : (
I have faced same problem. When i have uploaded dlls into bin folder at that time below error occur on the server. i need to upload again DictionaryService services class .
I am facing this issue as and when and just by excluding the web.config file and reuploading the DLL files again on the server the issue gets resolved.
Can anyone help me to understand why this issue is taking place and what is the solutions?
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted