Note that there are some explanatory texts on larger screens.

plurals
  1. POWhere is the BEST PRACTICES place to put a list of Countries in a MVC Application?
    text
    copied!<p>In a heavy enviroment application, we have Users, Locations, bla bla bla... and we use in many situations a call to a service where we retrieve the list of countries.</p> <p>Where is the 'best practice' or 'proper way' to implement this. This method is called in several places and many objects has a <code>List&lt;CountryVO&gt;</code> property.</p> <p>Specially considering using Razor views an often having to add this property to ModelViews</p> <p>The solution is using DAL / BLL / SERVICE / UI[s] architecture.</p> <p>Real Example:</p> <pre><code>public class User { ... ... public List&lt;DeliveryZoneVO&gt; DeliveryZones {get;set;} public User() { ... DeliveryZones = service.GetDeliveryZones().ToList(); } } </code></pre> <p>The class DeliveryZoneVO comes from a webservice, so one property is </p> <pre><code>int IdCountry </code></pre> <p>The class User have a list of DeliveryZoneVO as presented on the class, the 'problem' here, is since it retrieves the data from a web service, I only have the ID of the country.</p> <p>When I prepare the data in the controller to send to the View:</p> <pre><code>UserModelView userMV = new UserModelView(); userMV.user = service.GetUserById(1); ViewData.Model = userMV; </code></pre> <p>BUT, inside userMV.user, I have DeliveryZones with a list of DeliveryZoneVO objects with IdCountries.</p> <p>In the view, when I do (for example) :</p> <pre><code>@DisplayFor(m =&gt; m.user.DeliveryZones) </code></pre> <p>I want to show the Country Name, only have the ID. So i need a reference somewhere.. the question lies in where should that data needs to be placed that is considered BEST PRACTICES.</p> <p>Is having in all modelview (in the case of the example, the UserModelView() the property Countries with a List ?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload