Save and Publish not working at controller level in Umbraco 8 for me
I have been trying to submit a simple form with four fields using a surfacecontroller method in umbraco 8 for past 4 days, can anyone help where i might be making a mistake?
[HttpPost]
public ActionResult Createentry(entryViewModel model)
{
if (!ModelState.IsValid)
{
return CurrentUmbracoPage();
}
IContentService contentService = Services.ContentService;
var pId = Convert.ToInt32(id);
var parent = contentService.GetById(pId);
var content = contentService.CreateContent("sample", parent.GetUdi(), Entry.ModelTypeAlias);
{
content.SetValue("fullName", model.FullName);
}
if (model.Email != null)
{
content.SetValue("email", model.Email);
}
if(model.phone != null) {
content.SetValue("mobileNumber", model.MobileNumber);
}
if (model.FileUpload != null)
{
content.SetValue("entry", model.FileUpload.ToString());
}
contentService.SaveAndPublish(content, "en-US");
TempData.Add("CustomMessage", "Your form was successfully submitted at " + DateTime.Now);
return RedirectToCurrentUmbracoPage();
}
The form submits with data properly and this works properly but after saveand publish there is no id for created entry and no entry is created in backoffice either
Thanks for the response Damiaan, but i have tried disabling fileupload as well as made sure my aliases are all correct, no errors in debug as well, not sure what i am doing wrong at this point
Thanks Dave, My parent node is created properly and it has multiple cultures enabled, but if i remove this specified culture here i get an error that "cannot save without name".
Save and Publish not working at controller level in Umbraco 8 for me
I have been trying to submit a simple form with four fields using a surfacecontroller method in umbraco 8 for past 4 days, can anyone help where i might be making a mistake?
The form submits with data properly and this works properly but after saveand publish there is no id for created entry and no entry is created in backoffice either
Are you sure you have a "sample" document type?
The file upload may cause troubles. Disable it to be sure that is not the issue. Use this technique further to debug what line is causing issues.
Good luck! Kind
Thanks for the response Damiaan, but i have tried disabling fileupload as well as made sure my aliases are all correct, no errors in debug as well, not sure what i am doing wrong at this point
Are you using v8? Because there is no
CreateContent
method if I remember correctly.Just as a side question, but you do not allow the front-end to add content to the website right?
Kind regards
Damiaan
Yes, I am using version 8 and this is data submitted when user enters a data in a form from front-end
Hi Rabea,
Looking at your code it looks fine at first glance. However this seems to be a bit redundant.
You can use the CreateContent method with integer Id of the parent. So no need to retreive the parent item.
I see you save for a specific culture here. But is your doctype set up for varying by culture ?
Otherwise try to ommit the culture parameter,
And to be sure check if your parent node is not in the recycle bin. I know it sounds silly, but these kinds of thing happen.
Dave
Thanks Dave, My parent node is created properly and it has multiple cultures enabled, but if i remove this specified culture here i get an error that "cannot save without name".
Can you make a screenshot of the "cannot save without name" message.
I can not find this message in the umbraco source (probably not looking good enough).
Have you checked your logfiles to see if there is anything suspicious in there.
Dave
Nothing of note there as well :(
I think the problem is that you don't specify a culture specific name. Try setting the
IContent
name with:As you can see at the stacktrace the code fails on:
So, specifying the name for the specific cultures should be the fix. Check the related code files in the V8 code base:
https://github.com/umbraco/Umbraco-CMS/blob/853087a75044b814df458457dc9a1f778cc89749/src/Umbraco.Core/Persistence/Repositories/Implement/DocumentRepository.cs
https://github.com/umbraco/Umbraco-CMS/blob/853087a75044b814df458457dc9a1f778cc89749/src/Umbraco.Core/Models/ContentBase.cs
Thanks Corné, The issue was this one and also the file was not uploading using simply setvalue, commenting that out and setting culture seemed to work
is working on a reply...