2010-05-20 58 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