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 4258100
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:36:14+00:00 2026-05-21T05:36:14+00:00

I’m putting together my first MVC application and have a question about how to

  • 0

I’m putting together my first MVC application and have a question about how to properly accomplish my goal. Here’s what I’m attempting…

One area in my application presents a list of batches of data, a list of Batch objects. For each Batch, a user can choose to process its data. The processing consists of a set of steps which I will present to the user in a wizard-like chain of views.

Each Batch has a type. Batch A of type L might consist of records of X, and Batch B of type M might consist of records of Y. The steps in the wizard are going to change slightly depending on the batch type. What I don’t want to do is this (obviously poor code, just for illustration):

ProcessController

public ActionResult StepOne(int id)
{
    var batch = BatchRepository.Batch.SelectById(id);
    var records = BatchRepository.Data.SelectForBatch(batch);

    switch (batch.BatchType)
    {
        case "X":
            return View("TypeXStepOne", records);
        case "Y":
            return View("TypeYStepOne", records);
        default:
            return View();
    }

}

public ActionResult StepTwo(int id)
{
    var batch = BatchRepository.Batch.SelectById(id);
    var records = BatchRepository.Data.SelectForBatch(batch);

    switch (batch.BatchType)
    {
        case "X":
            return View("TypeXStepTwo", records);
        case "Y":
            return View("TypeYStepTwo", records);
        default:
            return View();
    }

}

...

And so on. This seems like a bad practice, and as my wizard might be 4 or 5 steps, and I currently have three different batch types, the amount of code in these actions becomes retardedly difficult to maintain.

What can MVC do for me in terms of managing this? I’d like to minimize the amount of work required if, for example, a fourth type was introduced.

I know that I’m probably going to have:

  • A partial view for each batch type
    and step in the wizard, there’s
    really no way around that, though some partial views might get shared.

So, would it be better for each batch type to have a dedicated controller? I suppose I could then do something like this, where the batch type becomes the controller name.

BatchController

public ActionResult Process(int id)
{
    var batch = BatchRepository.Batch.SelectById(id);
    return RedirectToAction("StepOne", batch.BatchType, new { id = batch.Id });
}

But this would depend on the Batch type name matching the controller name, and I don’t necessarily like that either. Update: Or, worst case, I have a single switch statement here with my three batch types, and then I can forward on to the appropriate controller.

So… ideas! I need ’em. And I’m no so far into this that I can’t start something new, I’m just throwing ideas around in my head as an MVC newbie. MVC must have something that allows dynamic view switching based on context, whether it be by fancy routing techniques or a “ViewFactory” or some other trickery.

Any feedback whatsoever would be greatly appreciated!

And just for anyone wondering, I am stuck on the .NET 3.5 and IIS6, which is why I’m back on MVC 2 instead of 3.

UDPATE

Here’s what I’m rolling with for now. I broke the BatchController into multiple controllers — one for each batch type. Since they are mostly the same I created an abstract WizardController that has these methods:

public abstract ActionResult Step(int batchId, int stepNumber);

protected ViewResult ViewStep(int stepNumber, object model)
{
    return View(string.Format("Process\Step{0}", stepNumber), model);
}

And in my derived controller(s), something like:

public override ActionResult Step(int batchId, int stepNumber)
{
    var data = BatchRepository.BatchType.SelectByBatchId(batchId);

    return ViewStep(stepNumber, data);
}

It’s quick and seems dirty but until I learn something better… thanks!

  • 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-21T05:36:15+00:00Added an answer on May 21, 2026 at 5:36 am

    Convention over configuration (the new hardcoding), something as simple as:

    public ActionResult Step(int stepNo, int id)
    {
        var batch = BatchRepository.Batch.SelectById(id);
        var records = BatchRepository.Data.SelectForBatch(batch);
        return View("Type"+batch.BatchType+"Step"+stepNo, records);    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and
I have a French site that I want to parse, but am running into
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.