I'm trying to create some content using razor. Everything seems to run fine and I'm not getting any exception but it is not creating any content. Any suggestions?
try { // Create new content, the last param is the userId and is optional [default = 0] var newContent = Model.ContentService.CreateContent("My new document", nodeId, "Task");
// Set property values newContent.SetValue("taskDuration", duration); newContent.SetValue("taskDate", date); newContent.SetValue("taskNotes", notes);
// Save (or save and publish) Model.ContentService.SaveAndPublish(newContent); } catch (Exception ex) { @Html.Raw(ex.Message); }
looks fine to me. What is "nodeId" in the context of this example i.e. the parent content item you expect this new content to be added to?
Also FYI, while there's no technical reason why you can't have this logic sitting in a razor view, it's better practice to have it in (or called from) a controller action.
CreateContent using razor
I'm trying to create some content using razor. Everything seems to run fine and I'm not getting any exception but it is not creating any content. Any suggestions?
try
{
// Create new content, the last param is the userId and is optional [default = 0]
var newContent = Model.ContentService.CreateContent("My new document", nodeId, "Task");
// Set property values
newContent.SetValue("taskDuration", duration);
newContent.SetValue("taskDate", date);
newContent.SetValue("taskNotes", notes);
// Save (or save and publish)
Model.ContentService.SaveAndPublish(newContent);
}
catch (Exception ex)
{
@Html.Raw(ex.Message);
}
looks fine to me. What is "nodeId" in the context of this example i.e. the parent content item you expect this new content to be added to?
Also FYI, while there's no technical reason why you can't have this logic sitting in a razor view, it's better practice to have it in (or called from) a controller action.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.