我正在尝试保存我的IContent呼叫child,但在这一行(contentService.SaveAndPublish(child);)上我收到以下错误:Object reference not set to an instance of an object.
if (child.HasProperty("navn"))\n{\n child.SetValue("navn", worker.Name.ToString(), "da-dk");\n}\ncontentService.SaveAndPublish(child);\nRun Code Online (Sandbox Code Playgroud)\n\n这就是我定义我的contentService:IContentService contentService = Umbraco.Core.Composing.Current.Services.ContentService;
我发现孩子们是这样的:
\n\nlong totalChildren;\n\nIEnumerable<IContent> children = contentService.GetPagedChildren(filialsParent.Id, 0, 100, out totalChildren);\nRun Code Online (Sandbox Code Playgroud)\n\n\xc2\xb4\n有人能指出这里出了什么问题吗?
\n我发现如果我这样做的话它就会起作用。
var umbf = Umbraco.Web.Composing.Current.Factory.GetInstance<IUmbracoContextFactory>();
using (var contextf = umbf.EnsureUmbracoContext())
{
var umbcontext = contextf.UmbracoContext;
IContentService cs = Umbraco.Core.Composing.Current.Services.ContentService;
cs.SaveAndPublish(child);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1436 次 |
| 最近记录: |