Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Rabea 34 posts 186 karma points
    Apr 30, 2019 @ 04:50
    Rabea
    0

    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

  • Damiaan 442 posts 1301 karma points MVP 6x c-trib
    Apr 30, 2019 @ 05:03
    Damiaan
    0

    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

  • Rabea 34 posts 186 karma points
    Apr 30, 2019 @ 05:23
    Rabea
    0

    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

  • Damiaan 442 posts 1301 karma points MVP 6x c-trib
    Apr 30, 2019 @ 05:35
    Damiaan
    0

    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

  • Rabea 34 posts 186 karma points
    Apr 30, 2019 @ 05:36
    Rabea
    0

    Yes, I am using version 8 and this is data submitted when user enters a data in a form from front-end

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Apr 30, 2019 @ 06:56
    Dave Woestenborghs
    1

    Hi Rabea,

    Looking at your code it looks fine at first glance. However this seems to be a bit redundant.

    var parent = contentService.GetById(pId);
    var content = contentService.CreateContent("sample", parent.GetUdi(), Entry.ModelTypeAlias);
    

    You can use the CreateContent method with integer Id of the parent. So no need to retreive the parent item.

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

    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

  • Rabea 34 posts 186 karma points
    Apr 30, 2019 @ 07:14
    Rabea
    0

    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".

  • Damiaan 442 posts 1301 karma points MVP 6x c-trib
    Apr 30, 2019 @ 08:54
    Damiaan
    0

    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).

  • Rabea 34 posts 186 karma points
    Apr 30, 2019 @ 08:57
    Rabea
    0

    enter image description here

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Apr 30, 2019 @ 07:20
    Dave Woestenborghs
    0

    Have you checked your logfiles to see if there is anything suspicious in there.

    Dave

  • Rabea 34 posts 186 karma points
    Apr 30, 2019 @ 08:31
    Rabea
    0

    Nothing of note there as well :(

  • Corné Strijkert 80 posts 456 karma points c-trib
    Apr 30, 2019 @ 09:55
    Corné Strijkert
    101

    I think the problem is that you don't specify a culture specific name. Try setting the IContent name with:

    var content = contentService.CreateContent("sample", parent.GetUdi(), Entry.ModelTypeAlias);
    content.SetCultureName("sample", "en-US");
    

    As you can see at the stacktrace the code fails on:

    DocumentRepository.EnsureInvariantNameExists(IContent content)

    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

  • Rabea 34 posts 186 karma points
    May 02, 2019 @ 08:41
    Rabea
    1

    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

Please Sign in or register to post replies

Write your reply to:

Draft