I am getting following error:
The model item passed into the dictionary is of type 'Cygnus.Global.ViewModels.StoreViewModel', but this dictionary requires a model item of type 'Cygnus.Global.ViewModels.ProductOrderViewModel'.
Following is my Model code:
public class StoreViewModel
{
public int Id { get; set; }
public List<StoreViewModel> Stores { get; set; }
}
Following is my Controller Code:
public ActionResult StoreProducts (StoreViewModel model)
{
CygnusInternalResponseViewModel response = new CygnusInternalResponseViewModel();
response = new Logic(CApplicationId, CurrentCompanyId).GetProductsByStoreId(model.Id);
var parentmodel = new ProductOrderViewModel() { Products = response.Model, Orders = new OrderViewModel() };
if (response.Success)
return View(model);
return View();
}
And following is my View Code:
NOTE: StoreViewModel exists in ProductOrderViewModel as a property
@model Cygnus.Global.ViewModels.ProductOrderViewModel
@foreach (var pd in Model.Products)
{
<p>
span class="cmtText"> | @pd.Name | @pd.UnitPrice </span>
</p>
}
@Html.LabelFor(m => m.Orders.SubTotal)
@Html.TextBoxFor(m => m.Orders.SubTotal, new { @readonly = "readonly", @style = "width:100px; float:right;margin-top:-21px;" })
I corrected my mistake in controller
public ActionResult StoreProducts (StoreViewModel model)
{
CygnusInternalResponseViewModel response = new CygnusInternalResponseViewModel();
response = new Logic(CApplicationId, CurrentCompanyId).GetProductsByStoreId(model.Id);
var parentmodel = new ProductOrderViewModel() { Products = response.Model, Orders = new OrderViewModel() };
if (response.Success)
return View(model);
return View();
}
To
public ActionResult StoreProducts (StoreViewModel model)
{
CygnusInternalResponseViewModel response = new CygnusInternalResponseViewModel();
response = new Logic(CApplicationId, CurrentCompanyId).GetProductsByStoreId(model.Id);
var parentmodel = new ProductOrderViewModel() { Products = response.Model, Orders = new OrderViewModel() };
if (response.Success)
return View(parentmodel );
return View();
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments