将值分配给Viewmodel [英] Assigning values to Viewmodel

查看:94
本文介绍了将值分配给Viewmodel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好..........

我有一个像list这样的linq变量...它从数据库的两个以上的表中检索一些值.............我如何创建一个存储值列表的viewmodel以及如何分配这个值从控制器到该视图模型的列表.........请帮助我............

Hi everyone..........

I have a linq variable like list ...it retrieves some values from more than two tables from database ............ how can i create a viewmodel to store list of values and how can i assign this list to that view model from controller......... please help me............

推荐答案

您好,

为此,您需要开发一个模型(类),该模型同时具有表中的属性,并且可以将此类模型的列表传递给控制器​​.
EX
Hi,

To do such an operation you require to develop a model(class) which has property from both the table and you can pass list of such a model to your controller.
EX
public class aaa
{
  table1filrd1{get;set;}
  table1filrd2{get;set;}
  table1filrd3{get;set;}
  table2filrd1{get;set;}
  table2filrd2{get;set;}
  table2filrd3{get;set;}
}


或者您可以开发单独的模型并将其分组为单个班级


or you can develop a separate models and club them in single class

public class a{....}
public class b{....}
public class c
{
  List<a> aa {get;set;}
  List <b> bb {get;set;}
}
</a>



最后一个选项是使用ViewData传递两个列表,但不建议
您可以参考

http://www.codeproject.com/script/Answers/Post.aspx?aid=485966 [^ ]



and last option is pass the both list using ViewData but it is not advisable
you can refer

http://www.codeproject.com/script/Answers/Post.aspx?aid=485966[^]


这篇关于将值分配给Viewmodel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆