要解决ASP.NET Core 2.2中的编辑领域问题,你可以使用以下步骤和代码示例:
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
}
[HttpGet]
public IActionResult Edit(int id)
{
// 根据id从数据库或其他数据源获取领域对象
Product product = GetProductById(id);
if (product == null)
{
return NotFound();
}
return View(product);
}
@model Product
[HttpPost]
public IActionResult Edit(Product product)
{
if (ModelState.IsValid)
{
// 在此处执行更新操作,将编辑后的领域对象保存到数据库或其他数据源
UpdateProduct(product);
return RedirectToAction("Index");
}
return View(product);
}
这样,当用户访问编辑页面并提交表单时,编辑操作将被处理并相应的领域对象将被更新。
请注意,上述代码示例仅作为参考。实际的实现可能会根据你的需求和数据访问方法的不同而有所变化。