У меня простой вопрос.
У меня есть модель, которая выглядит так:
public class AddEditChildProductModel
{
public string Name {get; set;}
public string Sku {get;set;}
........
public IEnumerable<AddEditPriceTierModel> PriceTiers {get;set;}
}
public class AddEditPriceTierModel
{
public int QtyStart {get;set;}
public int QtyEnd {get;set;}
........
}
У меня вопрос, как мне отредактировать коллекцию в том же виде?
Казалось бы, это было бы очень просто, может быть, я что-то упустил.
Спасибо !!
** Редактировать **
ОК, поэтому я использовал EditorTemplates, но теперь я получаю следующую ошибку:
The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable. When a change is made to a relationship, the related foreign-key property is set to a null value. If the foreign-key does not support null values, a new relationship must be defined, the foreign-key property must be assigned another non-null value, or the unrelated object must be deleted.
Это действие моего контроллера:
public ActionResult EditChildProduct(AddEditChildProductModel model)
{
if (!ModelState.IsValid)
return PartialView("AddEditChildProduct", model);
ChildProduct childProduct = productService.GetChildProductByID(model.ID);
AutoMapper.Mapper.Map<AddEditChildProductModel, ChildProduct>(model, childProduct);
foreach (var tier in childProduct.PriceTiers)
{
tier.ChildProduct = childProduct;
}
UnitOfWork.Commit();
return ListChildProducts(model.ProductID);
}
Разве это не должно работать, так как я получаю ChildProduct
с соответствующей коллекцией PriceTiers
и использую AutoMapper для сопоставления различий? Я сохраняю скрытые поля для полей PK и FK на PriceTier
.
Я немного растерялся.