dcsimg
Results 1 to 2 of 2

Thread: Best practice for populating model data

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2015
    Posts
    75

    Best practice for populating model data

    I'm using VS2019 with ASP.NET MVC. I just started learning MVC.

    I have a generic list of objects to hold a recordset in my model like this:


    Code:
    public class Test
    {
    
        public List<Row> Rows = new List<Row>();
    
    }
    
    public class Row
    {
         public string F1 = null;
         public string F2 = null;
    }
    I need to loop thru data in a table and populate the "Rows" list.

    Initially I had a method in class Test to populate Rows but apparently that is bad practice.

    Code:
    public class Test
    {
    
        public List<Row> Rows = new List<Row>();
    
        public void GetRows()
       {
            ...    
       }
    
    }
    
    public class Row
    {
         public string F1 = null;
         public string F2 = null;
    }
    So where should I populate the Rows list? If I put the code in the Controller won't that "junk up" the controller logic?

    Should I create another class for populating the list and call it from Controller? If so where would I create that class and is there a naming convention for that?

    Thanks!
    Last edited by madison320; Aug 29th, 2019 at 10:46 AM.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,406

    Re: Best practice for populating model data

    What you're looking for is an orchestrator... the controller is the entry point... it should then pass off to an orchestrator... the orchestrator's job is to then... orchestrate the actions behind the scenes... getting the data, creating what ever objects necessary, and getting the data for the return to the controller... when it;s done, it should return the data back to the controller, which then passes that back to the client.

    At least that's how we do it around here.


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width