Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8521741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:54:45+00:00 2026-06-11T06:54:45+00:00

I develop websites using web-forms, now I have a project where I am using

  • 0

I develop websites using web-forms, now I have a project where I am using MVC3 Framework with Rzor. My question is about some basic design patterns in MVC. I have a Webpage, where on left side i will Pull Categories from SQL Table, In Center I will Query another Sql Table, and few more all over the page.

So my question is…whats the best way to bring data into one webpage, all these queries are totally independant, do I need to create new MODEL for every Query? or there is a better way of doing it?

in WebForms I used user controls, where every user control had its own design & Sql Queries. I have heard about using Partial Views in MVC, but i am not sure, I guess i am having hard time understanding how to bring data into one webpage using different queries & show output on webpage.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T06:54:46+00:00Added an answer on June 11, 2026 at 6:54 am

    You should create a ViewModel. Look at Update below

    This is a model that represents your page. The elements you want to show in your view should exist in your ViewModel. You will populate the ViewModel in your controller and display them on the page.

    I’ve written an example of a shopping site page, with categories on the left and Products in the centre. Both entities would exist in different tables.

    Example:

    class MainPageViewModel
    {
      //this data is from a different table.
      //and goes on the left of the page
     public string Categories {get; set;}
      //this data is also from a different table.
      //and goes on the center of the page
     public List<Products> Products {get; set;}
    }
    

    In your controller:

    public class HomeController : Controller
    {
        // GET: /Home/
        public ActionResult Index()
        {
            MainPageViewModel vm = new MainPageViewModel();
            vm.Categories = GetCategories();
            //use the GetProducts() to get your products and add them.
            vm.Products.Add(...); 
            return View(vm); //pass it into the page
        }
        string[] GetCategories()
        {
         DataTable data = GetDataFromQuery("SELECT * FROM Categories WHERE..");
         //convert the data into a string[] and return it..
        }
        //maybe it has to return something else instead of string[]? 
        string[] GetProducts()
        {
         DataTable data = GetDataFromQuery("SELECT * FROM Products WHERE..");
         //convert the data into a string[] and return it..
        }
        DataTable GetDataFromQuery(string query)
        {
            SqlDataAdapter adap = 
                 new SqlDataAdapter(query, "<your connection string>");
            DataTable data = new DataTable();
            adap.Fill(data);
            return data;
        }  
    }
    

    Then in your view you display it appropriately:

    @model MainPageViewModel 
    
    @{ ViewBag.Title = "MainPage"; }
    
    <div id="left-bar">
      <ul>
        @foreach (var category in Model.Categories)
        {
            <li>@category</li>
        }
      </ul>
    </div>
    <div id="center-content">
        <ul>
        @foreach (var product in Model.Products)
        {
            <li>@product.Name</li>
            <li>@product.Price..</li>
            .....
        }
      </ul>  
    </div>
    

    Update

    This is about your comment where you mentioned that your database tables and columns change regularly.

    I can’t say for sure but maybe you shouldn’t be making tables like that everyday, maybe there is a better database design you could have, or maybe an RDBMS isn’t the right thing for you and you should look into a NoSql database (like MongoDB )

    Nevertheless if you continue with the above code I suggest putting this into a data layer class of its own.

    Also take a look at Dapper it’s a very thin data access layer that just gets objects from the database with sql queries or stored procedures. (Just exactly what you need) It’s made and used by stackoverflow.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My team is about to begin a web project using the Symfony2 framework. We
I develop websites using PHP and MySQL. What resources would a seasoned web developer
I have been learning to develop websites using ASP.NET MVC 2 for work... and
Recently I have started working with Codeigniter framework in order to develop RESTFul web
I am using MVC preview 2 framework to develop web sites and I am
I am trying to develop websites using Zend Framework. But I came to a
I need some advice from experts :) I will develop a website using PHP
I have been tasked to develop an interactive website using java & mysql: using
I am taking some time to learn how to develop asp.net mvc2 websites, but
I am entry level .Net developer and using it to develop web sites. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.