asp.net - How to parse data from ViewData -


i trying parse data viewdata not going well.

controller:

public actionresult listfilm()         {             mediacatalog mediacl = new mediacatalog();              // retrieve list of film media's             list<catalogdb.filmmedia> listfilmmedia = new list<catalogdb.filmmedia>();             listfilmmedia = mediacl.getallfilmmediatitles();              viewdata["filmlist"] = listfilmmedia.tolist();              return view();         } 

view:

<% foreach(var item in (viewdata["filmlist"] list<catalogdb.filmmedia>)) { %> <%=item.title %> <% } %> 

i noticed code written in view file parsed directly in source, reason not being executed code?

i use viewbag property, has been added asp.net mvc3. uses dynamic under hood, makes viewbag typed. (viewdata uses dictionary under hood , returns object , have cast).

so basically, instead of using viewdata["mypropery"] mytype, can directly call viewbag.myproperty , don't need cast (to "mytype").


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -