我在同一个视图中有两个类(模型)和两个文本框。第一个文本框应该绑定到第一个模型,第二个文本框应该绑定到第二个模型。我彻底搜查了它。我需要一个MVVM模式的例子。将数据从多个模型绑定到单个视图
-1
A
回答
1
我的模型
public class Customer
{
public int CustomerId { get; set; }
public string Title { get; set; }
public string Name { get; set; }
public string Address1 { get; set; }
public string Address2 { get; set; }
public string Area { get; set; }
public int MobileNumber { get; set; }
}
public class Account
{
public int AccountId { get; set; }
public string AccountType { get; set; }
}
我的视图模型
public class TaskManagerVM
{
private Customer CustomerObj = new Customer();
private Account AccountObj = new Account();
public int CustomerId
{
get { return CustomerObj.CustomerId; }
set { CustomerObj.CustomerId = value; }
}
public string Name
{
get { return CustomerObj.Name; }
set { CustomerObj.Name = value; }
}
public string Address1
{
get { return CustomerObj.Address1; }
set { CustomerObj.Address1 = value; }
}
public string Address2
{
get { return CustomerObj.Address2; }
set { CustomerObj.Address2 = value; }
}
public int AccountId
{
get { return AccountObj.AccountId; }
set { AccountObj.AccountId = value; }
}
public string AccountType
{
get { return AccountObj.AccountType; }
set { AccountObj.AccountType = value; }
}
}
我绑定第一个文本框来查看模型的客户ID属性,它连接到第一个模型,customer.cs 我绑定第二个文本框查看连接到第二个模型的模型的Account ID属性,account.cs
它是否正确?
+0
看不到任何错误。你在正确的道路上。 ViewModel可以从多个来源或模型中获取数据,并可以查看视频.. –
+0
你做得很好。让我知道你在哪里被击中.. –
+0
感谢您的评论朋友。我首先不知道并提出了这个问题。然后我想象这个解决方案。 –
相关问题
- 1. 将单个视图模型绑定到单个记录
- 2. 如何将单个视图绑定多个模型?
- 3. 多个视图和数据模板绑定到相同的视图模型
- 4. 绑定多个视图模型
- 5. 从数据绑定视图模型
- 6. 如何将多个模型绑定到Spring Web Flow中的单个视图?
- 7. 将多个数据类型绑定到GridView中的单个列
- 8. 绑定到另一个视图模型
- 9. 将多个值绑定到模型上
- 10. 将多个ng模型绑定到单个HTML元素
- 11. 将多个函数绑定到视图的单击事件
- 12. 将数组数据绑定到视图模型 - knockout.js
- 13. 多个视图绑定到多个ViewModels
- 14. 如何使用Knockout.js将多个视图绑定到单个ViewModel
- 15. 绑定多个模型在骨干网的单一视图
- 16. 如何将模型绑定到视图?
- 17. 将资源绑定到视图模型
- 18. 绑定多个文件输入数据到AngularJS数据模型
- 19. 如何将多个模型分配到单个视图?
- 20. 使用JQuery将数据绑定到视图中的模型ajax
- 21. 将选择查询数据绑定到视图模型列表
- 22. KendoUI:将视图模型绑定到数据源更改
- 23. ruby on rails:将视图绑定到非数据库模型
- 24. 使用视图模型将数据表绑定到DataGrid
- 25. 我可以使用默认的模型绑定器将多个表单绑定到单个模型吗?
- 26. 绑定到单个对象在视图模型
- 27. 笨:从多个模型到视图加载数据
- 28. 将数据绑定到多个数据透视表项
- 29. 将不同视图模型绑定到每个页面
- 30. UWP - 将多个网格视图绑定到列表清单
发布您到目前为止尝试过的东西。 –
@Ayyappan Subbramanian。我发布了我做的答案。请对此发表评论。 –
向下投票导致我被该网站阻止发布新问题。朋友首先请在downvoting之前的理由,以便我可以更正 –