I'm using Asp.Net MVC 5 with EF 6.
I have a Model, let's call it "Checkout". It has the following properties:
int BuyerId
List<CheckoutItem> Items
CheckoutItem has the following properties:
int ItemId
decimal Price
bool IsPaid
I want to have a view first display EditorFor -> BuyerId. When the user enters a BuyerId, the view should update with the Checkout data, the items displayed in a list in which the user can click a "remove" link to remove that item from the current transaction (the View's current Model). When the user clicks on the submit button, I want the controller to update the items in the Checkout.Items list with IsPaid = true.
I understand all of the logic needed for all of this. The problem I'm having is how this all works withing the MVC context.
Currently I have Checkout.cshtml whose Model is Buyer (accessed by BuyerId) which has a textbox for the user to enter the BuyerId and an empty <div>
. Using jquery on .focusout I use .ajax to call the controller and return a partial view, "_CheckoutDetail". _CheckoutDetail uses Checkout Model to display the information in the model.
Currently _CheckoutDetail has a form, but when I submit it from the partial view, the binding isn't working.
If this is all clear what I'm trying to do, my question is, what is the best way to accomplish this? I expected my partial view to post its Model back to the controller, but it isn't working. I've tried both
public async Task<ActionResult> CheckoutDetails(CheckoutViewModel checkout)
and
public async Task<ActionResult> CheckoutDetails([Bind(Include = "BuyerId,Items")] CheckoutViewModel checkout)
in my controller definition. In both cases I receive a message "The name 'checkout' does not exist in the current context".
Thank you for your help.