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
Post a Comment