Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sitecore MVC multi step form

I am developing multi step form with sitecore and mvc. In each step I need the sitecore context and I am using controller rendering for the same. Now as sitecore works I need to add the controller name and action for my rendering so basically I can only use one controller action for each rendering.

In my case I have used the same action name but different parameters type for each step in multi step form. Ideally I would like to have different controller action name for each step within multi step form. Can anyone please help me with that?

Thanks

like image 855
Tech Learner Avatar asked Jun 12 '26 11:06

Tech Learner


1 Answers

I'm not sure I understand the question completely. Are you trying to use a single .cshtml file for all the steps? If so, you can define multiple controller renderings for the same View in the Sitecore CMS. In the renderings section, define each step of your multi-step form as separate controller renderings. You can use the same controller for each, but specify a different action.

In your controller logic, you can specify to return the same View, but pass different properties into your Model object.

For example, you might do something like this:

public ActionResult Step2(){
   var context = RenderingContext.Current.PageContext.Item;
   var otherParams = "SomethingForStep2";
   var model = new MyModelObject(context, otherParams);
   var view = this.View("Path/To/My/View", model);

   return view;
}

In the example above, I assume you have defined some sort of Model object where you can pass in whatever parameters you need so that your view can use this to render.

If you are using different views, then you will just return a different view for each action, again passing in a model to the View to help it render.

like image 103
Jay S Avatar answered Jun 15 '26 22:06

Jay S



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!