如何将值从多个列表传递给ViewModel
我有两个模型列表和主模型。我需要访问和存储价值到模型属性。不确定如何使用ViewModel进行操作?以前,我正在使用ViewData列表,现在我要测试ViewModel。
<---Model--->
public class Master
{
public List<Table1> T1 { get; set; }
public List<Table2> T2 { get; set; }
}
public class Table1
{
public string sample1 { get; set; }
public string sample1 { get; set; }
}
public class Table2
{
public string sample1 { get; set; }
public string sample2 { get; set; }
}
<--Controller-->
Master master = new Master();
var getSamples = _db.dbSamples.Where(y => y.sample == "xxxx");
foreach(var row in T1) <<---- I need help correcting this part. I believe this is not right...
{
foreach (var item in getSamples)
{
row.sample1 = item.A;
row.sample2 = item.B;
}
}
return View(master);
I have two model list and master model. I need to access and store value to the model properties. not sure how to do this using a viewModel? previously I was using viewData list and now I wan to test viewModel.
<---Model--->
public class Master
{
public List<Table1> T1 { get; set; }
public List<Table2> T2 { get; set; }
}
public class Table1
{
public string sample1 { get; set; }
public string sample1 { get; set; }
}
public class Table2
{
public string sample1 { get; set; }
public string sample2 { get; set; }
}
<--Controller-->
Master master = new Master();
var getSamples = _db.dbSamples.Where(y => y.sample == "xxxx");
foreach(var row in T1) <<---- I need help correcting this part. I believe this is not right...
{
foreach (var item in getSamples)
{
row.sample1 = item.A;
row.sample2 = item.B;
}
}
return View(master);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您要做的就是这样。如果不是这样,请详细说明这个问题。
更新的代码。相应地更改变量名称。
I assume that what you are trying to do is this. If it is not, please elaborate on the question.
Updated code. Change variable names accordingly.