Widget create variant not working

Hendrik Clercx asked on June 29, 2023 13:26

I converted a .NET framework 4.8 Kentico 13.0.111 to .NET core 6.

I noticed that the Widget variant functionality doesn't work anymore. The widgets that already had multiple variants configured still work on the MVC website. When I switch to another persona, I get to see the matching variant of that widget. I can also edit the content of a variant. However in the Page Builder functionality, for a new widget, I can't add new variants. That part doesn't seem to be working anymore.

So I open the Widget variant popup, I select the persona I want, I click on 'Add variant' but nothing happens at this point: Image Text

I don't see any error in my console, network tab or Kentico Event Log.

First it opens the modal, the info is fetched via this call:

https://localhost:44323/cmsctx/pm/6415b8ce-8072-4bcd-8e48-9d7178b826b7/culture/nl-BE/wg/5f26ce66-dbd7-46dd-8324-302fb4c2adbe/readonly/0/ea/1/h/965351dfb81505ed3585f4bd52d199eec05af377374c93e454471616f7661585/-/kentico.pagebuilder/personalization/conditiontypes/myProjectNameSpace.personalization.isinpersona/isinpersona/index?cultureCode=nl-BE&instance=1505f7fc-a751-4697-959d-3cf4e039fd0e&uh=6ff6a8ceda2a8c202d83a4a23075e9a1a4069e285506623a29ec9e9bdc39f323&administrationurl=https%3A%2F%2Flocalhost%3A44393%2F&uiculture=en-us&editmode=1

Response:

response local

Then when selecting a persona, it triggers the validate action:

https://frontend.local/cmsctx/pm/36983b36-8502-4a42-a274-545af16312f6/culture/nl-BE/wg/5f26ce66-dbd7-46dd-8324-302fb4c2adbe/readonly/0/ea/1/h/1fef8829c7d20d6f06a9568f278417a6d65e10c796db43c31c775f9e7b3b3e65/-/kentico.pagebuilder/personalization/conditiontypes/myProjectNameSpace.personalization.isinpersona/isinpersona/validate?editmode=1&instance=e9ef5a9e-10b7-4ee2-b895-5cfe4d743627&uh=fcfdfcdc401a688a2af03084c665d2a44a6085598cf2debf6a266b662a098c5c&administrationurl=https://cmsurl.local&uiculture=en-us

However, the response is not correct here. It should return something like this: (screenshot from working environment)

expected response

But the response is the same as the index method:

response local

Next to this, during my conversion I have this folder in my MVC project:

folder structure

I am trying to figure out of this is something generated by Kentico or added by previous developers? Since .NET core is using wwwroot to serve files, the Page Builder might miss some scripts? Do I need to move these files to wwwroot as part of the migration or can I just ignore this? I think these files came from installing Nuget Kentico.Xperience.AspNet.Mvc5 or Kentico.Xperience.Libraries

Any advice?

Correct Answer

Hendrik Clercx answered on July 3, 2023 16:22

Okay so apparently there was custom code behind the /index and /validate. Not sure how I missed this in the first place...

But this explains a lot...

[HttpPost]
public IActionResult Validate(IsInPersonaViewModel viewModel)
{
    if (!ModelState.IsValid)
    {
        viewModel.AllPersonas = GetAllPersonas();
        return PartialView("Personalization/ConditionTypes/_IsInPersonaConfiguration", viewModel);
    }

It was returning the same response as /index in case the model was not valid. And because I am using .net core, the property AllPersonas was not valid anymore when it was empty:

public class IsInPersonaViewModel
{
    [Required]
    [Display(Name = "Persona Code Name")]
    public string PersonaCodeName { get; set; }

    public List<IsInPersonaListItemViewModel> AllPersonas { get; set; }
}

An "?" solved it.

0 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on June 29, 2023 16:15

What was the project in before you converted it? Was it version 13 MVC5? Or an earlier major version like version 12? I believe that folder you're mentioning is part of an MVC5 project. I'd highly recommend installing the Dancing Goat .NET Core sample site and compare. That "Kentico" directory should NOT be there for a .NET Core 6 project.

Seems like you have some cleanup that needs to happen in your Core project.

0 votesVote for this answer Mark as a Correct answer

Hendrik Clercx answered on June 29, 2023 16:26

Was first MVC K12. Then upgraded to K13. Now doing the conversion from K13 framework 4.8 to K13 .NET core 6.

That's what I thought, I'll remove that folder. But unfortunately not related to the problem then...

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on June 29, 2023 16:38

As suggested, clean up your core project to closely match what the DancingGoat project has. Also review the DancingGoat CMS project and compare that as well. Since you "upgraded" the CMS vs. started with a new version, you may have some caching issues with the CMS javascript files.

0 votesVote for this answer Mark as a Correct answer

Hendrik Clercx answered on June 29, 2023 16:54

Production is running Kentico 13. There is not much changed during the conversion to .net core regarding the CMS app since that is still on framework 4.8.

I'll have a good look at the differences between DancingGoat and my MVC, see if there's anything important missing.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on June 29, 2023 19:28

Production CMS and public site are both on v13.0.111? Is the public site MVC5 or .NET 6?

As I mentioned prior, if you upgraded the CMS application, there could be lingering code out there. I'd suggest starting with a fresh copy of v13.0.111 and if you have any custom CMS code to migrate that into the project.

Once you review the DG base projects with your code, clear the cache for the CMS in your browser and get your project rebuilt, you should be set.

0 votesVote for this answer Mark as a Correct answer

Hendrik Clercx answered on July 3, 2023 12:39

Yes, they're both running v13.0.111. I did the following tests:

Setup:

  • CMS version 1 (deployed on PROD)
  • CMS version 2 (current)
  • MVC version 1 (.NET framework, deploy on PROD)
  • MVC version 2 (.NET core, current)

The following combinations work (on local machine), I can create new widget variants:

  • CMS version 1 with MVC version 1 (as expected, also situation on PROD)
  • CMS version 2 with MVC version 1

These combinations do not work:

  • CMS version 1 with MVC version 2
  • CMS version 2 with MVC version 2

So the problem is not with the CMS. I compared with Dancing Goat project, but didn't find anything notable.

I tried disabling scripts both in Dancing Goat and in my working combination to break it but I wasn't successful with this. I was still able to create a widget variant.

I enabled all exceptions during debugging to see if it would catch something, but that wasn't the case.

Currently going through the DLLS of Kentico to see if I can find out why my response is not matching the one of the working combination. If anyone can help out where this code is situated? This '/isinpersona/validate'

http://myMvcWebApp/cmsctx/pm/6415b8ce-8072-4bcd-8e48-9d7178b826b7/culture/nl-BE/wg/5f26ce66-dbd7-46dd-8324-302fb4c2adbe/readonly/0/ea/1/h/965351dfb81505ed3585f4bd52d199eec05af377374c93e454471616f7661585/-/kentico.pagebuilder/personalization/conditiontypes/MyProjectNamespace.personalization.isinpersona/isinpersona/validate/?editmode=1&instance=3143026f-25e1-4d9b-a3af-d6943a2d9c7d&uh=29b598270eaab62c878836e903e5ec39234abdf09d0f0ee75c65b61e17a7a6ef&administrationurl=https://myCmsUrl&uiculture=en-us

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.