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
Umbraco version 8.16.0
I have found some ideas, but still no success.
One example uses: @inject IContentService Services
The code fails with: The name 'inject' does not exist in the current
Link to example: Code
Another example uses:
IContentService contentService = new ApplicationContext.Current.Services.ContentService();
The code fails with:
Link to second example: code
Ultimately, I would like to resolve all of these reference issues, but I am open to other suggestions as well.
Your first example with @inject is 'how to do things' for Umbraco V9 which is the most recent release of Umbraco based on .NET 5, which allows you to use the 'inject' keyword...
... but if you are running Umbraco 8.16, then it's the second approach and the ContentService you are after.
programatically updating textbox example:
The key thing is how to get access to the ContentService, and this depends a little on where you are writing the code, eg a View or Controller or in a custom c#class...
If you are in a controller or view you can access the ContentServices, from a special 'Services' gateway property... eg
var contentService = Services.ContentService;
but if you are in a custom c# class this is possible via dependency injection (the ApplicationContext example would be the V7 way)
There is an example of how to inject a service here into a c#class:
Secondly when you use class names in .net, eg 'IContentService' or 'ContentService' or 'ApplicationContext' you have to tell your code where to get these things from, and to do this you use 'using statements'...
... annoyingly using statements are often missing from examples!
but I think if you have
at the top of your file, that would cover the things you might be trying to do!
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted