0

I have model "Test", on the first view user enters "Title", "CountOfWords", "Level". Depending on the value of the CountOfWords field, I generate the input fields in the second view and fill the Words list with them, and I want to display all this general data in the third view. How can I pass first three first fields to second view and then these three fields together with Words list to third view?

My model "Test":

public class Test
{
    [Required]
    public string Title { get; set; }

    [Required]
    public string Level { get; set; }

    [Required]
    public int CountOfWords { get; set; }

    [Required]
    public DateTime Date { get; set; }

    public List<Word> Words { get; set; }
    public CreateModel()
    {
        Date = DateTime.Now;
        Words = new List<Word>();
    }
}

1 Answer 1

0

You could create a separated model for each step, with its own validations and use Session to store the steps.

public class ModelStep1
{
    ... properties
}
public class ModelStep2
{
    ... properties
}

In the controller:

public ActionResult SubmittedStep1(ModelStep1 model)
{
    if (ModelState.IsValid)
    {
        Session["Step1Data"] = model;
        return View("Step2View", CreateModelForStep2());        
    }
    else 
    {
        return View(model);
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.