asp.net mvc - MVC 3 - Accessing ModelMetaData for IEnumerable Model? -


i'm trying access modelmetadata custom htmlhelper i'm working on. htmlhelper has signature ...

public static mvchtmlstring datagrid<t>(this htmlhelper<t> htmlhelper){} 

the (razor) view looks ...

@model ienumerable<logmyassets.models.contactmodel> .... @html.datagrid() 

my problem can't access modelmetadata model it's ienumerable. thought following:

var model = (ienumerable<t>)htmlhelper.viewdata.model; var metadata = model.elementat(0).getmetadata();  public static modelmetadata getmetadata<tmodel>(this tmodel model) {    return modelmetadataproviders.current.getmetadatafortype(null, typeof(tmodel)); } 

but stangely enough following error:

unable cast object of type 'system.collections.generic.list`1[lma.models.contactmodel]'  type 'system.collections.generic.ienumerable`1[system.collections.generic.ienumerable`1 

i though could cast generic list generic ienumerable. missing something?

i don't understand t defined in (ienumerable<t>), guess t ienumerable<something>, means you're trying cast ienumerable<ienumerable<something>>


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -