2010-05-10 166 views
0
 public ActionResult Create() 
     { 
      try 
      { 
       var Group = GroupRepository.FindAllGroups(); 
       ViewData["Group"] = GroupRepository.FindAllGroups(); 
       ViewData["Feature"] = FeatureRepository.FindAllFeatures(); 
       DataTable dt = FeatureRepository.GetAllFeatures(); 

       // TODO: Add insert logic here 
       Group group = new Group() 
       { 
        dtm_CreatedDate = DateTime.Now, 
        int_CreatedBy = 1 

       }; 
       return View(group); 

      } 
      catch 
      { 
       return View(); 
      } 
     } 

我想发送数据表以及组对象到视图。我将如何做到这一点asp.net mvc发送值查看

回答

4

创建新的特定类,这将让该集团的对象为成员和任何对象,你需要查看使用

public class MySpecificViewClass 
{ 
    public Group Group; 
    ... 
} 

,并在此之后指定这个类实例作为View参数

return View(new MySpecificViewClass { Group = group, ... }); 
+0

+1,你打我吧,只是暴露数据表作为属性MySpecificClass – 2010-05-10 08:39:42

+1

不是真的,我不会这样做。而是将其复制到更通用的列表或IEnumerable。 DataTable感觉如此ADO.NET和WebForms,只是我的2美分.. – mare 2010-05-10 09:27:19

+0

好的,谢谢我的点积分可能会好得多 – maztt 2010-05-10 10:50:15