Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use model binding with jquery
    text
    copied!<p>The MVC model binder is doing a great job of picking up values from my page and passing them into my action methods as properties in my complex input.</p> <p>I'm trying to create a shopping cart type of page, where the user can configure a list of line items, then submit the entire order.</p> <p>At first I was using Ajax forms for when the user wanted to add an item -- the list of existing lineitems would be passed back to the controller, a new lineitem would be added, and a partial view for the list returned.</p> <p>Unfortunately, looks like you can't redirect to another page after an Ajax form is submitted. I don't want to do it in jQuery though, because I don't want to deal with explicitly creating the list of complex objects when the MVC model binder does such a good job of it.</p> <p>EDIT: To clarify, here is my problem:</p> <p>I want my form to have 2 operations, both of these require the list of lineitems to be passed back.</p> <p>It is my understanding that I have to do at least one of these operations using javascript. Either:</p> <ol> <li>Use an HtmlForm to submit the entire order, return a new view </li> <li>Add the lineitem with jQuery when the "add item" button is clicked</li> </ol> <p>OR</p> <ol> <li>Use an AjaxForm to dynamically add new lineitems</li> <li>Use javascript to do the redirect after the order is submitted, but this means I have to submit the data using javascript as well</li> </ol> <p>Is there a way I can do this without using javascript? I don't want to create the list of lineitems myself with JSON when the movdel binder does it without any work on my part.</p>
 

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