Copied to clipboard

Flag this post as spam?

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


  • Thomas 23 posts 143 karma points
    Jan 10, 2022 @ 16:32
    Thomas
    0

    Creating a multi-step form in Umbraco with ViewComponent

    Hi

    I'm having some challenges trying to get a multi-step form to work in Umbraco 9 using a ViewComponent.

    My post method looks like this:

        [HttpPost]
        [ValidateAntiForgeryToken]
        public IActionResult SubmitForm(IndmeldelsesformViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return CurrentUmbracoPage();
            }
    
            if (model.NextPage)
            {
                model.CurrentPage++;
            }
    
            if (model.PrevPage)
            {
                model.CurrentPage--;
            }
    
            model.CurrentPage++;
    
            return CurrentUmbracoPage();
        }
    

    and my ViewComponent is a simple one like this:

    public IViewComponentResult Invoke()
        {
            return View(new IndmeldelsesformViewModel()
            {
                CurrentPage = 1
            });
        }
    

    I can submit the form, but I'm having trouble figuring out how to retain the view model. How do I modify the view model in the SubmitForm function and return it to the ViewComponent?

  • Carlos Gomes 38 posts 184 karma points
    Jul 22, 2022 @ 18:49
    Carlos Gomes
    0

    Hi Thomas,

    Did you manage to solve this issue? I'm facing exactly the same problem: can't figure out how to keep the Model on each step submission.

    I have tried to use return PartialView() or View() but that way, it loses the page layout.

    Does anyone know how to build a Multi-Step form in Umbraco 10?

    Thanks

  • Mahender Singh 39 posts 171 karma points
    May 27, 2023 @ 05:26
    Mahender Singh
    0

    Hi @UmbracoTeam,

    Can you please help us to solve this issue using view components

  • Nick Bloodworth 23 posts 96 karma points
    May 27, 2023 @ 13:10
    Nick Bloodworth
    0

    I gave up and used JotForm instead

    Nick

  • Huw Reddick 1932 posts 6722 karma points MVP 2x c-trib
    May 31, 2023 @ 11:40
    Huw Reddick
    0

    For your View component, try defining it as below

    public IViewComponentResult Invoke(IndmeldelsesformViewModel model)
        {
            nodel.CurrentPage = 1;
            return View(model);
        }
    

    It's difficult to say precisely what you need without seeing your page templates.

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

Please Sign in or register to post replies