<detail-form asp-for="@Model"
all-properties="true"
edit-mode-default="true"
form-method="POST"
form-action="@Url.Action("Edit", "DetailForm")"/>
/*
DetailWidthsAsString in ColumnLayout specifies percentage width
for different device screen widths, while WidthsAsString
percentage width when shown in-line within a collection control.
Oder specify the order columns are rendered. Higher Order come first.
All setting, included Display/Name may be overriden by providing
a column definition TagHelper within the control definition.
*/
public class SimpleProductViewModel
{
public int? Id { get; set; }
[MaxLength(128)]
[ColumnLayout(DetailWidthsAsString = "100 50")]
[Required]
[Display(Name = "Name", Order = 400)]
public string Name { get; set; }
[ColumnLayout(DetailWidthsAsString = "60 30")]
[Display(Name = "Price", Order = 300)]
public decimal Price { get; set; }
[Display(Name = "Cur", Order = 280)]
[ColumnLayout(WidthsAsString = "10", DetailWidthsAsString = "40 20")]
public Currency ChosenCurrency { get; set; }
[ColumnLayout(DetailWidthsAsString = "20")]
[Display(Name = "Av", Order = 230)]
public bool Available { get; set; }
}
public class SimpleProductViewModelDetail: SimpleProductViewModel
{
[MaxLength(256)]
[Display(Name = "Description", Order = 100)]
[ColumnLayout(DetailWidthsAsString = "80")]
[DisplayFormat(NullDisplayText = "no description available")]
public string Description { get; set; }
}
public async Task<IActionResult> Edit(int? id)
{
if (!id.HasValue) id = 1;
var model = await repository
.GetById<SimpleProductViewModelDetail, int>(id.Value);
return View(model);
}
[HttpPost]
public async Task<ActionResult> Edit(SimpleProductViewModelDetail model)
{
if (ModelState.IsValid)
{
repository.Update(false, model);
await repository.SaveChanges();
return RedirectToAction("Edit", new { id = model.Id });
}
return View(model);
}