C # MVC - general wizard form
I am trying to create a form master where I can define steps. For each step, I need to have a contoller and a view based on the step type. I tried to do this on generic types, but I have a problem with a running method on a controller that is generic.
Here's an example.
public interface IExampleInterface { }
public abstract class WizardBaseController<T> : Controller where T : IExampleInterface
{
public abstract List<T> Steps { get; set; }
public abstract ActionResult RenderStep(T step);
public virtual ActionResult RenderNext(T step)
{
var index = Steps.IndexOf(step);
return RenderStep(Steps[index+1]);
}
}
public class ExampleClass : IExampleInterface { }
public class WizardController<T> : WizardBaseController<ExampleClass> where T : ExampleClass
{
public override List<ExampleClass> Steps { get; set; }
public override ActionResult RenderStep(ExampleClass step)
{
//do stuff
throw new NotImplementedException();
}
public virtual ActionResult RenderStep(T step)
{
throw new NotImplementedException();
}
public ActionResult CreateSteps()
{
Steps = new List<ExampleClass>
{
new AnotherExampleClassA(),
new AnotherExampleClassB(),
new ExampleClass(),
new AnotherExampleClassB(),
new AnotherExampleClassA(),
};
return RenderNext(Steps.First());
}
}
public class AnotherExampleClassA : ExampleClass { }
public class ChildWizzardConotroller : WizardController<AnotherExampleClassA>
{
public override ActionResult RenderStep(AnotherExampleClassA e)
{
//do stuff
throw new NotImplementedException();
}
}
public class AnotherExampleClassB : ExampleClass { }
public class AnotherChildWizzardConotroller : WizardController<AnotherExampleClassB>
{
public override ActionResult RenderStep(AnotherExampleClassB e)
{
//do stuff
throw new NotImplementedException();
}
}
but when i try to call action from wizardController i get 404 error
<a href="@Url.Action("CreateSteps", "Wizard")">Trigger Action</a>
I'm not sure if my way of doing this is correct.
Basically my goal is to create a wizard with different types of steps and call different methods based on the type of steps. For example, to call a RenderStep method (with parameter type - ExampleClass) I want to call a method that is in WizardController when RenderStep (with parameter type - AnotherExampleClassA) calls a method in ChildWizzardConotroller, etc.
source to share
No one has answered this question yet
Check out similar questions: