Hi There,
I have a complex model in view. But, i sended simple example for subject.
Main View Model :
public class ErpProductModel
{
public string Title { get; set; }
public string Code { get; set; }
public string ShortCode { get; set; }
public int MinStock { get; set; }
public int ShelfLife { get; set; }
public int CategoryId { get; set; }
public int TaxCategoryId { get; set; }
public decimal AmountInProduct { get; set; }
public int MeasureWeightId { get; set; }
public int CountryId { get; set; }
public int StatusId { get; set; }
public List<ErpProductPackageTypeModel>? PackageTypes { get; set; } = [];
}
PackageTypes Model :
public record ErpProductPackageTypeModel
{
public int? ProductId { get; set; }
public string Barcode { get; set; }
public int Quantity { get; set; }
public string? PackageType { get; set; }
public int PackageTypeId { get; set; }
public List<SelectListItem> AvailablePackageTypes { get; set; } = [];
}
View Source :
<script type="text/x-kendo-tmpl" id="packageTypeTemplate">
<div class="card widget widget-info">
<div class="card-body">
<div class="widget-info-container">
<div class="widget-info-image" style="background: url('@Url.Content("/Assets/Images/barcode_mock.png")')"></div>
<h5 class="widget-info-title">#=Barcode#</h5>
<p class="widget-info-text">#=PackageType# / #=Quantity# PCS</p>
</div>
</div>
</div>
</script>
@(Html.Kendo().ListView<ErpProductPackageTypeModel>()
.Name("package-types")
.BindTo((IEnumerable<ErpProductPackageTypeModel>)Model.PackageTypes)
.TagName("div")
.Bordered(false)
.Layout("grid")
.Grid(p=> p.Cols(4).Gutter(20))
.ClientTemplateId("packageTypeTemplate")
.HtmlAttributes(new { @class= "rubi-listview package-types" })
.DataSource(dataSource =>
dataSource.Ajax()
.Batch(true)
.ServerOperation(false))
)
Controller Post Method :
[HttpPost]
public virtual async Task<IActionResult> EditAsync(ErpProductModel model)
{
var erpProduct = await _erpProductService.GetErpProductAsync(model.Id);
if (erpProduct == null)
return RedirectToAction("List");
erpProduct = model.ToEntity(erpProduct);
await _erpProductService.UpdateErpProductAsync(erpProduct);
return RedirectToAction("Edit", new { id = erpProduct.Id });
}
My scenario is simple;
I have a product save screen. There are package types depending on this product. If all I want is to fill the package types, I will make various updates, additions or deletions on this data.
Thank you in advance for your help.
Why do we need to get a telerik license? No support, no community!