在Umbraco7中,我使用以下代码从C# (控制器)以编程方式生成代码
使用ContentService.CreateContent和下面是相同的代码
int parentID = 1100;
var request = ContentService.CreateContent("New Node Name", parentID, ContactUsForm.ModelTypeAlias);
request.SetValue(ContactRequestItem.GetModelPropertyType(C => C.FirstName).PropertyTypeAlias, FormModel.FirstName);
ContentService.PublishWithStatus(request);现在在Umbraco 8中
它是在要求
Udi ParentId
获取错误“无法将'int‘转换为'Umbraco.Core.Uid’”。
我已经搜索了很多,但找不到Umbraco 8的任何东西。
所以现在的问题是我们如何在Umbraco 8中从一个控制器创建一个节点?
发布于 2019-04-25 00:46:59
该解决方案如以下链接所示
public IContentService _contentService { get; set; }
public TestController(IContentService contentService)
{
_contentService = contentService;
}
public override ActionResult Index(ContentModel model)
{
var parentId = new Guid("3cce2545-e3ac-44ec-bf55-a52cc5965db3");
var request = _contentService.Create("test", parentId, ContentPage.ModelTypeAlias);
_contentService.SaveAndPublish(request);
return View();
}发布于 2019-04-24 19:38:50
首先获取父节点(这可以通过int ID来完成),然后再从中获取UDI如何?就像这样
var parent = ContentService.GetById(1100);
var request = ContentService.CreateContent("New Node Name", parent.GetUdi(), ContactUsForm.ModelTypeAlias);发布于 2020-12-17 15:34:45
在Umbrco8中,您需要父Udi来创建一个新节点。为此,您可以先获取父节点,然后使用父节点获取Udi,如下所示:
var parentNode = ContentService.GetById(1100);
var parentUdi = new GuidUdi(parentNode.ContentType.ToString(), parentNode.Key);然后,您可以调用CreateContent方法并将parentUdi作为参数传入:
var request = ContentService.CreateContent("New Node Name", parentUdi, ContactUsForm.ModelTypeAlias);
ContentService.SaveAndPublish(request);https://stackoverflow.com/questions/55813647
复制相似问题