c# - ViewModel and Interface cannot work out to to get data -
i'm having hard time trying work out, how can create viewmodel interface,
i have been trying follow few examples online i.e
http://www.rachelappel.com/use-viewmodels-to-manage-data-amp-organize-code-in-asp.net-mvc-applications
and
http://geekswithblogs.net/michelotti/archive/2009/10/25/asp.net-mvc-view-model-patterns.aspx
but cannot work, help appreciated, code far below.
public class travelguideviewmodel { private readonly igetcountrydetails _igcd; public displaycountrydetails displaycountrydetails { get; set; } public travelguideviewmodel(igetcountrydetails igcd) { _igcd = igcd; } //trying displaycountrydetails here, seek not work } ======================update===============
public class travelguideviewmodel { private readonly igetcountrydetails _igcd; public displaycountrydetails displaycountrydetails { get; set; } public travelguideviewmodel(igetcountrydetails igcd) { _igcd = igcd; } public travelguideviewmodel asia() { var countries = _igcd.displaycountriesoftheworlddetails() .where(a => a.strcountrycontinent == "asia").firstordefault(); homecoming countries.strcountry.asenumerable(); << not work } }
the reason .asenumerable() not work because homecoming type on function travelguideviewmodel not enumerable.
try like...
public travelguideviewmodel asia() { var countries = _igcd.displaycountriesoftheworlddetails() .where(a =>a.strcountrycontinent == "asia).firstordefault(); homecoming new travelguideviewmodel(countries); } in order create accessible view, viewmodel has contain pointer it. think of viewmodel cup view trying drink out of. not drink itself. handy have, not much if not fill something.
c# asp.net-mvc asp.net-mvc-4
No comments:
Post a Comment