2010-05-20 60 views
1

我有我的观点与如何删除IEnemurable在asp.net mvc的

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<StudentInfo>>" %> 

一个观点,如果我有IEnumerable的我可以做的foreach ..

但在此之前,我需要访问属性对于StudnetInfo ..有

Public class StudentInfo 
{ 
    public Studentdetails sd {get;set;} 
    public classDetails cd {get;set;} 
} 

<% foreach(var e in Model){%> 
<div> 
<%=Html.DisplayFor(x=>e.StdentEdit) %> 
    <div> 
    <span> 
    <% Html.RenderAction("Details", "Home", new { @t = e }); %> 
     </span> 
    </div> 
</div> 
<% } %> 

请任何人可以帮助我走出

StudentInfo CLAS ..如何让亲StudentInfo foreach循环以上的perties ...

如果我删除IEnemurable我能做到这一点..但我需要有Ienemurable用于..的RenderAction

有没有我们可以做到这一点任何其他方式? 感谢

回答

1

Ë将类型StudentInfo的,请致电:

e.GetType().GetProperties() 

如果你需要抓住从模型的通用参数类型的情况下直接迭代,我建议这个现有的SO问题:

How to get the type of T from a member of a generic class or method?

(第二个答案应该适合你)

+0

我需要保持之前foreach循环?但我不能在那里? 如何只在foreach循环上方访问属性一次? 谢谢 – kumar 2010-05-20 16:31:50

+0

我把这个问题与foreach循环之前解释如何做的问题联系起来。 – jfar 2010-05-20 17:57:51