c# - Linq doesn't work in MVC View -


i have list in controller

list<string> mylist = new list<string>(); mylist.add(astring);  viewbag.linklist = mylist; 

and in view trying do

@viewbag.linklist.first() 

and giving me error: 'system.collections.generic.list' not contain definition 'first'

if do

@viewbag.linklist[0]

it works fine.

i put @using system.linq in view. missing something? linq works inside view?

viewbag dynamic. first() extension method on ienumerable<t>. extension methods don't work on dynamic references.

you must first cast list ienumerable<string> before calling first().

@((viewbag.linklist ienumerable<string>).first()) 

note plain ienumerable not work, since .first() not defined it.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -