Question

I am having trouble passing a property value from one model to another,

I have a property referenced in the OrderTotalsModel here:

public string OrderTotal { get; set; }

I need that to show in the popUpOrderSummary View which uses the ShoppingCartModel,

I have created a property in this model:

public string popUpOrderTotal { get; set; }

I am aware that i need to pass the value of this property from the OrderTotalsModel to the ShoppingCartModel by using the ShoppingCartController,

I have so far added this code below the PrepareShoppingCartModel method:

model.popUpOrderTotal =

I have tried:

model.popUpOrderTotal = OrderTotalsModel.OrderTotal;
Was it helpful?

Solution

If you need to use the same value in 2 models, you need to retrieve it from the same place.

If you are setting the value for OrderTotal in your controller, set it in the same way for the ShoppingCartModel e.g. by retrieving it from the database or calculating it.

If the value is set or updated in a view, this value needs to be posted back to an action where you can either save it for later use, or use it immediately to display another view such as your shopping cart.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top