Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Make sure you cancel the default action of the submit button by returning false from your callback:</p> <pre><code>$('#addExperience').click(function() { CallSomeAction(); return false; // &lt;!-- that's important to prevent the form being submitted normally }); </code></pre> <hr> <p>UPDATE:</p> <p>After at last you have shown your code here's the problem:</p> <pre><code>[HttpPost] public ActionResult AddCar(UserViewModel model) </code></pre> <p>The action parameter is called <code>model</code>. But you also have a property inside <code>UserViewModel</code> which is called <code>Model</code> which is conflicting. The default model binder doesn't know which one to bind. </p> <p>So one possibility is to rename your action argument:</p> <pre><code>[HttpPost] public ActionResult AddCar(UserViewModel uvm) </code></pre> <p>and on the client side:</p> <pre><code>data: JSON.stringify({ uvm: model }) </code></pre> <hr> <p>UPDATE 2:</p> <p>You have the following line in your javascript:</p> <pre><code>var model = @Html.Raw(Json.Encode(Model)); </code></pre> <p>The problem is that your GET Index action in WizardController doesn't pass any view model to the view:</p> <pre><code>[HttpGet] public ActionResult Index() { return View(); } </code></pre> <p>So when you look at the generated source code of your page you will notice:</p> <pre><code>var model = null; </code></pre> <p>As a consequence you cannot expect to get anything other than <code>null</code> in your <code>AddCar</code> action. </p> <p>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. </p> <p>So you probably want something like this:</p> <pre><code>function AddCars() { $.ajax({ url: '@Url.Action("AddCar")', type: 'POST', data: $('form').serialize(), success: function(result) { alert('successful'); } }); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload