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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:30:56+00:00 2026-05-27T17:30:56+00:00

Updated Question Recently I need to implement a multi step wizard in ASP.NET MVC

  • 0

Updated Question

Recently I need to implement a multi step wizard in ASP.NET MVC 3. After some research I was able to find this solution.

http://afana.me/post/create-wizard-in-aspnet-mvc-3.aspx

So I followed the example exactly as the have it except the minor changes listed below:

@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>User</legend>
        <div class="wizard-step">
            @Html.Partial("UserInfo", this.Model)
        </div>
        <div class="wizard-step">
            @Html.Partial("Email", this.Model)
        </div>
        <div class="wizard-step">
            @Html.Partial("Cars", this.Model)
        </div>
        <p>
            <input type="button" id="back-step" name="back-step" value="< Back" />
            <input type="button" id="next-step" name="next-step" value="Next >" />
        </p>
    </fieldset>
}

As you can see I am using Partial View to render each steps.

Then I proceeded to create a ViewModel that would be used for this view:

public class UserViewModel
    {
        public UserViewModel()
        {

        }

        [Required(ErrorMessage="Username")]
        public string UserName
        {
            get;
            set;
        }

        public string FirstName
        {
            get;
            set;
        }

        public string LastName
        {
            get;
            set;
        }

        public string Email
        {
            get;
            set;
        }

        public string Make
        {
            get;
            set;
        }

        public string Model
        {
            get;
            set;
        }
    }

In the Cars Partial View I have the following code set up:

@model MVC2Wizard.Models.UserViewModel
<div class="editor-label">
    @Html.LabelFor(model => model.Model)
</div>
<div class="editor-field">
    @Html.EditorFor(model => model.Model)
    @Html.ValidationMessageFor(model => model.Model)
</div>
<div class="editor-label">
    @Html.LabelFor(model => model.Make)
</div>
<div class="editor-field">
    @Html.EditorFor(model => model.Make)
    @Html.ValidationMessageFor(model => model.Make)
</div>
<div>
    <p>
        <input id="addCar" type="submit" value="Add Car" />
    </p>
</div>
<script type="text/javascript">

    $("#addCar").click(function () {
        AddCars();
        return false;
    });

    function AddCars() {

        var model = @Html.Raw(Json.Encode(Model));

        $.ajax({

            url: '@Url.Action("AddCar")',
            type: 'POST',
            contentType: 'application/json; charset=utf-8',
            data: JSON.stringify({model: model}),
            success:function(result)
            {
                alert('successful');
            }

        });
    }

</script>

Here is my WizardController that will get called when Action is performed.

        // GET: /Wizard/

        [HttpGet]
        public ActionResult Index()
        {
            return View();
        }


        [HttpPost]
        public ActionResult Index(UserViewModel Person)
        {
            if (ModelState.IsValid)
                return View("Complete", Person);

            return View();
        }

        [HttpPost]
        public ActionResult AddCar(UserViewModel model)
        {
            return null;
        }

SO HERE IS MY PROBLEM:
Everything works great except the model parameter in the AddCar HTTPPost is always null when the action is performed! How do I set up the code so that the User Inputs are passing in during the HTTPPost. Also I need to take “Car” info and add it into a collection. Buts that’s step 2.

  • 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-27T17:30:56+00:00Added an answer on May 27, 2026 at 5:30 pm

    Make sure you cancel the default action of the submit button by returning false from your callback:

    $('#addExperience').click(function() {
        CallSomeAction();
        return false; // <!-- that's important to prevent the form being submitted normally
    });
    

    UPDATE:

    After at last you have shown your code here’s the problem:

    [HttpPost]
    public ActionResult AddCar(UserViewModel model)
    

    The action parameter is called model. But you also have a property inside UserViewModel which is called Model which is conflicting. The default model binder doesn’t know which one to bind.

    So one possibility is to rename your action argument:

    [HttpPost]
    public ActionResult AddCar(UserViewModel uvm)
    

    and on the client side:

    data: JSON.stringify({ uvm: model })
    

    UPDATE 2:

    You have the following line in your javascript:

    var model = @Html.Raw(Json.Encode(Model));
    

    The problem is that your GET Index action in WizardController doesn’t pass any view model to the view:

    [HttpGet]
    public ActionResult Index()
    {
        return View();
    }
    

    So when you look at the generated source code of your page you will notice:

    var model = null;
    

    As a consequence you cannot expect to get anything other than null in your AddCar action.

    This being said I suppose that you are not willing to send the view model to this action. You are willing to send the 2 values that the user entered in the form.

    So you probably want something like this:

    function AddCars() {
        $.ajax({
            url: '@Url.Action("AddCar")',
            type: 'POST',
            data: $('form').serialize(),
            success: function(result) {
                alert('successful');
            }
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm writing some code and have recently come across the need to implement
Question Updated for Bounty In Flash I need to load a dynamically generated XML
The background to this question is that I need to use some user session
UPDATED QUESTION Since the ctor is not supported by .NETCF (public FileStream(IntPtr handle, FileAccess
Updated question, see below I'm starting a new project and I would like to
Updated question given Andrew Hare's correct answer: Given the following C# classes: public class
UPDATED QUESTION: Ok, I am going to simplify my question since I don't really
Here is the updated question: the current query is doing something like: $sql1 =
ORIGINAL (see UPDATED QUESTION below) I am designing a new laboratory database that tests
UPDATED: Added one more question (Question #4). Hi all, I'm building myself a custom

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.