1

I have a view with

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

in my view if i have IEnumerable I can do foreach..

but before that i need to access the properties for StudnetInfo..

StudentInfo clas having

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>
<% } %>

please can anybody help me out.. how to get the properties of StudentInfo above the foreach loop...

if i remove IEnemurable I can do that.. but i need to have Ienemurable for RenderAction..

is there any other way we can achieve this? thanks

kumar
  • 2,944
  • 18
  • 60
  • 89

1 Answers1

1

e will be of type StudentInfo, call:

e.GetType().GetProperties()

If you need to grab the generic argument type from your Model directly without iterating I recommend this existing SO question:

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

(2nd answer should work for you)

Community
  • 1
  • 1
John Farrell
  • 24,673
  • 10
  • 77
  • 110
  • do I need to keep before foreach loop? but i can not e there? how to access the properties only once above the foreach loop? thanks – kumar May 20 '10 at 16:31
  • I linked to the question explaining how to do it before the foreach loop. – John Farrell May 20 '10 at 17:57