【发布时间】:2016-12-13 13:23:56
【问题描述】:
我想先说声对不起,因为我是这门编程语言的新手,如果我说错话或做错了什么,请原谅我。
我创建了一个包含 3 个类库的项目(其中 1 个包含来自 sql server 的表)。我根据来自“http://tutlane.com/tutorial/aspnet-mvc/how-to-use-viewmodel-in-asp-net-mvc-with-example”的教程制作了一个 ViewModel,现在我希望能够更新这些表中的数据,但我不知道如何。我试图做某事,但失败了。 `命名空间 BOL2.ViewModel { 公共课 NIRIO { [钥匙] 公共 int ID { 获取;放; } 公共 int 编号 { 获取;放; } 公共可空日期{获取;放; }
public int NirID { get; set; }
[DisplayName("TypeID")]
public int TipID { get; set; }
public int SupplierID { get; set; }
public int ProductID { get; set; }
public Nullable<System.DateTime> EntryDate { get; set; }
public Nullable<System.DateTime> ExitDate { get; set; }
public int Quantity { get; set; }
public decimal Price { get; set; }
public decimal Total { get; set; }
public BOL2.tbl_NIR tbnir;
public BOL2.tbl_I_O tblio { get; set; }`
这是我的视图模型。它包含来自这 2 个表的数据(tbl_NIR,前 3 个,其他来自 tbl_I_O。我在研究中看到他们有一个存储库类,但我现在不应该为 viewmodel 做另一个类,或者我想使用我已经拥有的 2?非常感谢任何帮助。
【问题讨论】:
-
我找到了这个问题的答案,所以这个话题现在已经解决了。在另一个表的编辑控制器中添加:“tbl_I_O oi = db.tbl_I_O.Where(x => x.NirID == id).First();”在 HttpGet 中。这个答案适用于像我这样如何在没有 viewmodel 的情况下使用 ADO.net Model 数据库的人。希望对您有帮助,对任何拼写错误表示抱歉。
标签: sql-server entity-framework model-view-controller