首页 > 解决方案 > 带有实体框架 6 更新页面的 Asp.net 网络表单

问题描述

我正在使用 asp.net webforms,并且我是 Entity Framework 的初学者。我需要知道如何制作更新页面并将数据从页面发送到方法(绑定),而不必逐字段绑定并保存更改。

假设我有这个类:

public class Fiche
{
    [Key]
    public int Id { get; set; }
    public string mrmme  { get; set; }
    public string nometprenom { get; set; }
    public string adresse { get; set; }
    public string ville { get; set; }
    public string cp { get; set; }
    public string tele { get; set; }
    public string portable { get; set; }
    public string datenaissance { get; set; }
    public string email { get; set; }
    public string situation { get; set; }
    public string profession { get; set; }

    #region // Santé & Prévoyance
    public string typesp { get; set; }
    public string nombresassures { get; set; }
    public string regime { get; set; }
    public string nbrenfants { get; set; }
    public string mutuelleactuelle { get; set; }
    public string tarifcontrat { get; set; }
    public string niveaugaranties { get; set; }
    public string mutuelle { get; set; }
    #endregion 

    public string Createdbynom { 
        get {
            return Data.Db.Users.Find(Createdby).nom;
        }
    }

    public string Affectedtonom
    {
        get
        {
            return Data.Db.Users.Find(Affectedto).nom;
        }
    }

    public ICollection<Contrat> Contrats { get; set; }
    public ICollection<Commentaire> Commentaires { get; set; }

    public string Createdby { get; set; }
    [ForeignKey("Createdby")]
    public ApplicationUser createuser { get; set; }

    public string Affectedto { get; set; }

    [ForeignKey("Affectedto")]
    public ApplicationUser affetcteduser { get; set; }
}

如果我想创建一个表单来更新这个模型,我有很多字段。我需要为每个字段创建文本框,当我单击“提交”按钮时,我需要从每个文本框中获取每个值并绑定到模型并调用SaveChnages

这是网络表单中更新数据库数据的唯一方法吗?

有什么方法可以将我的表单中的数据绑定到我的更新方法?

标签: c#asp.netwebformsentity-framework-6

解决方案


推荐阅读