c# - 带有实体框架 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++ - 当前形式的“std::exception”是多余的吗?
- reactjs - React Native Audio 向后端发送语音注释
- python - 深度学习无法运行 model.fit 函数
- asp.net-core-middleware - 在 Per-request 依赖项中使用多个实现的中间件
- javascript - Jquery自动增加和减少输入
- oracle - PL/SQL: PL/SQL: ORA-00942: 表或视图不存在
- android - getViewTreeObserver 用于 2 个视图
- go - 生成邀请码的字符串编号
- grammar - 用列表扩展 Antlr 语法文件
- json - 将 JSON 发送到 Django 后端