如何在asp.net mvc中删除IEnemurable

时间:2021-05-16 14:30:46

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..

在我看来,如果我有IEnumerable我可以做foreach ..

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

但在此之前,我需要访问StudnetInfo的属性..

StudentInfo clas having

StudentInfo clas有

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...

请任何人帮助我..如何获得在foreach循环之上的StudentInfo的属性...

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

如果我删除IEnemurable我可以做到这一点..但我需要Ienemurable为RenderAction ..

is there any other way we can achieve this? thanks

有没有其他方法可以实现这一目标?谢谢

1 个解决方案

#1


1  

e will be of type StudentInfo, call:

e将是StudentInfo类型,请致电:

e.GetType().GetProperties()

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

如果您需要直接从模型中获取泛型参数类型而不进行迭代,我建议使用现有的SO问题:

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

如何从泛型类或方法的成员中获取T的类型?

(2nd answer should work for you)

(第二个答案对你有用)

#1


1  

e will be of type StudentInfo, call:

e将是StudentInfo类型,请致电:

e.GetType().GetProperties()

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

如果您需要直接从模型中获取泛型参数类型而不进行迭代,我建议使用现有的SO问题:

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

如何从泛型类或方法的成员中获取T的类型?

(2nd answer should work for you)

(第二个答案对你有用)