Copied to clipboard

Flag this post as spam?

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


  • Thomas 4 posts 84 karma points
    18 days ago
    Thomas
    0

    Creating a multi-step form in Umbraco 9 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?

Please Sign in or register to post replies

Write your reply to:

Draft