Sab Ra
Sab Ra

Reputation: 51

Cannot save content with an empty name on content save at controller level in Umbraco 8

I am getting this error on saving and Publish "Cannot save content with an empty name" at controller level in Umbraco 8 I have a simple method in surface controller after form submit, which has a file upload and name and email, but after save and publish, I get this error that "Cannot save content with an empty name"

IContentService contentService = Services.ContentService;
var content = contentService.CreateContent("samplename", udi, sample.ModelTypeAlias);
content.SetValue("entry", model.FileUpload);

 contentService.SaveAndPublish(content);

Before this it worked fine in umbraco 7 for me.

Upvotes: 1

Views: 913

Answers (3)

Anh-Duc
Anh-Duc

Reputation: 164

CreateContent() only sets the Node name, but not the culture specific name of the content.

You will need to use SetCultureName(). This method sets the culture sepcific name, which is the empty name value that the error is complaining about on the SaveAndPublish()


IContentService contentService = Services.ContentService;
var content = contentService.CreateContent("samplename", udi, sample.ModelTypeAlias);

// You will need to set the culture specific name
content.SetCultureName("sampleName", culture)

content.SetValue("entry", model.FileUpload);

contentService.SaveAndPublish(content);

Upvotes: 0

Sab Ra
Sab Ra

Reputation: 51

So for anyone facing the same issue, the answer i found was to set the culture if u have multi cultures enabled for your site

contentService.SaveAndPublish(content, "en-US");

Upvotes: -1

Jannik Anker
Jannik Anker

Reputation: 3425

Does it work when you give the node a name? I'm thinking that all Umbraco content (at least as a rule of thumb) needs a unique URL, which cannot be created if the node has no name. Might be a new sanity check for v8, but a good one as far as I see it.

Upvotes: 0

Related Questions