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 6115735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:07:33+00:00 2026-05-23T15:07:33+00:00

I have a reliable and tested import method between an .xls spreadsheet[1] that returns

  • 0

I have a reliable and tested import method between an .xls spreadsheet[1] that returns a DataTable. I’ve located this in my service layer, not data as only the workbook gets persisted as an uploaded file, but now I’m wondering where and how to produce an HTML representation of this DataTable. I would prefer to avoid two loops in my view. I have a variable number of columns in the DataTable.

[1] Using an OleDb interface. I know it’s archaic but it works.

  • 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-05-23T15:07:33+00:00Added an answer on May 23, 2026 at 3:07 pm

    DataTables are weakly typed. I hate weak typing.

    Here’s an alternative approach: using view models, strongly typed views and display templates. So start by defining a view model which will represent the information you are willing to display:

    public class MyViewModel
    {
        public IEnumerable<ColumnViewModel> Columns { get; set; }
        public IEnumerable<RowViewModel> Rows { get; set; }
    }
    
    public class ColumnViewModel
    {
        public string Name { get; set; }
    }
    
    public class RowViewModel
    {
        public IEnumerable<CellValueViewModel> Values { get; set; }
    }
    
    public class CellValueViewModel
    {
        public string Value { get; set; }
    }
    

    then you could have a controller action which will populate this view model. If you already have some service layers that spits DataTables, you could map those tables to the aforementioned view model. For the purpose of this demo let’s hardcode:

    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            var model = new MyViewModel
            {
                Columns = new[] 
                { 
                    new ColumnViewModel { Name = "column1" }, 
                    new ColumnViewModel { Name = "column2" }, 
                    new ColumnViewModel { Name = "column3" }, 
                },
                Rows = new[]
                {
                    new RowViewModel 
                    {
                        Values = new[] 
                        {
                            new CellValueViewModel { Value = "1x1" },
                            new CellValueViewModel { Value = "1x2" },
                            new CellValueViewModel { Value = "1x3" },
                        }
                    },
                    new RowViewModel 
                    {
                        Values = new[] 
                        {
                            new CellValueViewModel { Value = "2x1" },
                            new CellValueViewModel { Value = "2x2" },
                            new CellValueViewModel { Value = "2x3" },
                        }
                    },
                    new RowViewModel 
                    {
                        Values = new[] 
                        {
                            new CellValueViewModel { Value = "3x1" },
                            new CellValueViewModel { Value = "3x2" },
                            new CellValueViewModel { Value = "3x3" },
                        }
                    }
                }
            };
            return View(model);
        }
    }
    

    and the last part is the view (~/Views/Home/Index.cshtml):

    @model MyViewModel
    
    <table>
        <thead>
            <tr>
                @Html.DisplayFor(x => x.Columns)
            </tr>
        </thead>
        <tbody>
            @Html.DisplayFor(x => x.Rows)
        </tbody>
    </table>
    

    and our display templates:

    ~/Views/Home/DisplayTemplates/ColumnViewModel.cshtml:

    @model ColumnViewModel
    <th>
        @Html.DisplayFor(x => x.Name)
    </th>
    

    ~/Views/Home/DisplayTemplates/RowViewModel.cshtml:

    @model RowViewModel
    <tr>
        @Html.DisplayFor(x => x.Values)
    </tr>
    

    ~/Views/Home/DisplayTemplates/CellValueViewModel.cshtml:

    @model CellValueViewModel
    <td>
        @Html.DisplayFor(x => x.Value)
    </td>
    

    And that’s pretty much all. As you can see we have written exactly zero loops in our views and we ended up with a nice <table> structure representing an Excel Worksheet.

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

Sidebar

Related Questions

The only reliable method that I a have found for using a script to
I have android.permission.READ_OWNER_DATA but I can't find any reliable code that would explain how
Well... that's it. I need something simple and reliable (doesn't have to have fancy
Say you have a link with a relative path that looks like this: <a
I have the main website hosted by a reliable static web hosting service. Which
What's the most reliable way to have JavaScript communicate between tabs/windows of the same
I have to write a reliable, totally-ordered multicast system from scratch in Python. I
Does anyone have an example of script that can work reliably well across IE/Firefox
I have a full trust XBAP which connects using reliable sessions to a remote
I have a link inside a div that floats to the right of the

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.