Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6643949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:06:38+00:00 2026-05-26T00:06:38+00:00

I have a registration page in my application. It has 3 states and 1

  • 0

I have a registration page in my application. It has 3 states and 1 error state(If any error comes):

  1. Fill Basic Information
  2. Select Package
  3. Say Thanks
  4. Error

Now I want to use state pattern here. First I created a console application which is OK. Now I want to implement this logic in my MVC application but I am confused about the structure. I mean how many views, models and controller I need and where to place my logic.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:06:38+00:00Added an answer on May 26, 2026 at 12:06 am

    1 controller: RegistrationController

    6 action methods:

    • GET+POST for Index (fill in basic info)
    • GET+POST for Package
    • GET for Thank you
    • GET for Error

    This is rough code to make your mind going:

    public class RegistrationController : Controller
    {
        public ActionResult Index()
        {
            RegistrationState model = RegistrationState.Init();
            // just display the "Fill Basic Info" form
            return View(model);
        }
    
        [HttpPost]
        public ActionResult Index(RegistrationState data)
        {
            // process data and redirect to next step
            this.TempData["RegState"] = data;
            if (!this.ModelState.IsValid || data.State == State.Error)
            {
                // error should handle provided state and empty one as well
                return RedirectToAction("Error");
            }
            return RedirectToAction("Package");
        }
    
        public ActionResult Package()
        {
            RegistrationState data = this.TempData["RegState"] as RegistrationState;
            if (data == null)
            {
                return RedirectToAction("Error");
            }
    
            // get packages and display them
            IList<Package> model = this.repository.GetPackages();
            return View(new Tuple.Create(data, model));
        }
    
        [HttpPost]
        public ActionResult Package(RegistrationState data)
        {
            // process data blah blah blah
        }
    
        // and so on and so forth
        ....
    }
    

    As you can see you still have to write some MVC-related code to act upon state changes. In my example everything’s done in action methods. But action filters could be used as well. If you can’t come up with a general action filter that can serve many different state objects then it’s best to just write the code in action methods.

    Another approach

    If you know Asp.net MVC good enough you could take this a step further and write a state machine ControllerFactory that would work along with routing in a sense as:

    {StateObjectType}/{State}
    

    ControllerFactory would therefore be able to parse view data to a known state object type and pass execution to particular action. According to state. This would make it a specially state machine suited Asp.net MVC application.

    The more important question is of course whether you can create the whole application with this pattern or are there just certain parts of it that should work like this. You could of course combine both approaches and provide appropriate routing for each.

    Important notices

    1. You should be very careful how you define your error state, because entering invalid field data shouldn’t result in error state but rather in data validation errors that actually display within the view beside the field with invalid data (ie. invalid date provided as 13/13/1313). Your error state should only be used for actual object state error that’s not related to user input. What would that be is beyond my imagination.

      As mentioned in my comment you should check out some Asp.net MVC intro videos and you’ll see how validation works in Asp.net MVC. Also rather simple stuff.

    2. State pattern of this kind is not something a regular Asp.net MVC developer would use, because it would most likely complicate code more than taking the normal approach. Analyse before you decide. Asp.net MVC is very clean code wise so adding additional abstraction over it may become confusing. And your domain model (state classes) would most likely have a much more complex code as simple POCOs with data annotations.

      In your case data validation would also be more complicated (when used with data annotations) because you object should be validated according to its state which may be different between states. POCO objects are always validated the same. This may mean that we may use more classes but they are smaller, simpler and easier to maintain.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a basic web app in place: it has a registration page, a
I need a city/state/country Dynamic Drop-Down List in my Wordpress registration page. I have
I have written the registration page in my CodeIgniter application. Everything works fine, and
I have created a django application. The application has a registration form. I inserted
I have a CakePHP application with user registration. On the users page, I want
Im using Symfony and Twig in a Silex application. I have a registration page
I am preparing a registration page using JSF/Spring webflow&mvc application. I have added two
i have a small form on SharePoint application page: <form method=post id=registration-form action=default.aspx class=form-general
I have a registration page with the following code below: in the views: def
I have a registration page, and because of content issues we have to request

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.