控制器进行编辑 .

// POST: Clients/Edit/5
    // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
    // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
    [HttpPost]
    [ValidateAntiForgeryToken]
    public async Task<IActionResult> Edit(Guid id, [Bind("ClientID,DOB,Name,NameID,Address,AddressID,ContactDetails,GPDoctors")] Clients clients)
    {
        if (id != clients.ClientID)
        {
            return NotFound();
        }

        if (ModelState.IsValid)
        {
            try
            {
                _context.Update(clients);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ClientsExists(clients.ClientID))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }
            return RedirectToAction("Index");
        }
        return View(clients);
    }

在“创建”表单中编辑数据时,数据将保存在新行中,而不是正在编辑和保存的外表中的原始数据 . 两个表中存在的Guid ID外键将替换为外表中新行的Guid . 但是,主表中的数据已正确保存 .

我是Asp.net核心和ef核心的新手,所以任何帮助和指导都会非常有用 .

编辑1客户端模型

using IWCaseManagerWebApp.Models;
using System;
using System.ComponentModel.DataAnnotations;

namespace IWCaseManager.Models
{
public class Clients
{
    [Key]
    public Guid ClientID { get; set; }

    public virtual Names Name { get; set; }
    public virtual Addresses Address { get; set; }
}
}

地址模型儿童

using System;
using System.ComponentModel.DataAnnotations;

namespace IWCaseManagerWebApp.Models
{
public class Addresses
{
    [Key]
    public Guid AddressID { get; set; }

    [Required]
    [StringLength(64)]
    public string Street { get; set; }

    [Required]
    [StringLength(32)]
    public string Town { get; set; }

    [Required]
    [StringLength(32)]
    public string County { get; set; }

    [StringLength(8, MinimumLength = 4)]
    public string Postcode { get; set; }

    [Required]
    public bool Validated { get; set; }
}
}