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

  • Home
  • SEARCH
  • 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 319989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:42:44+00:00 2026-05-12T08:42:44+00:00

so after a few weeks, i have got my head around asp.net mvc and

  • 0

so after a few weeks, i have got my head around asp.net mvc and have converted two webforms sites over. In addition to just the port, did some refactoring to have clean seperate of model, controller and view code.

One pattern that i see that i think still needs improvement is the following and i would like advice or feedback on these items as i am not sure how bad these smells are.

  1. Problem: HTML rendering knowledge in your controller – its very easy to have your business logic generate a bunch of HTML and shove it in ViewData and then have your view be a bunch of code that looks like this:

    `<%= Html.Encode(ViewData[“Title”]) %>

    `<%= Html.Encode(ViewData[“Content”]) %>

    `<%= Html.Encode(ViewData[“Footer”]) %>

What is the best solution for this? I obviously want to avoid this logic in my view? Should i shove the data down to the client and have this “rendering” logic in HTMLHelper classes

I end up with code like this in the controller class that builds up HTML tables . .

Stringbuilder gridBuilder = new StringBuilder();

        while (index < objDS.Count)
        {
            // start of table row
            gridBuilder.AppendLine("<tr align=\"center\">");
            for (int column = 0; column < numberOfColumns; column++)
            {
                if (index < objDS.Count)
                {
                    int record = (index) + ((objDS.CurrentPageIndex) * 12);
                    DataRow dr = photosDataSet.Tables[0].Rows[record];
                    gridBuilder.AppendLine("<td width=\"187.5\" valign=\"top\">");
                    int pictureNumber = Convert.ToInt32(dr.ItemArray[0].ToString());
                    string picnum = pictureNumber.ToString().PadLeft(3, '0');
                    int picNumberlink = pictureNumber - 1;
                    string image = "/pics/" + AlbumName + "/Thumbnails/" + AlbumName + "-pic" + picnum + ".jpg";
                    gridBuilder.AppendLine("<a id=\"picLinks_" + record + "\" class=\"picLinks\" href=''><img class=\"instant ishadow50\"  src=\"" + image + "\"></img></a>");
                    gridBuilder.AppendLine("<br/>");
                    gridBuilder.AppendLine(dr.ItemArray[1].ToString());
                    gridBuilder.AppendLine("</td>");
                }
                index++;
            }
            gridBuilder.AppendLine("</tr>");
        }
        gridBuilder.AppendLine("</table>");

        ViewData["Content"] = gridBuilder.ToString();
  • 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-12T08:42:44+00:00Added an answer on May 12, 2026 at 8:42 am

    The answere is – you souldn’t have html in your controller. If you can’t use the grid from MvcContrib as suggested then you sould create a class that takes the DataTable and outputs the html – in an overridden ToString method or a specific method that you call .

    And use it like :

    <%= new MyGridGenerator(DataTable ..) %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been stumbled on this for a while and after a few weeks
I'm new to Python and Django and have over the past few weeks managed
I have been noticing, over the last few weeks, that my installation of VS2008
After few weeks break, I'm trying to expand and extend my knowlege of templates
EDIT: a few weeks after I posted this question Evan Coury wrote an excellent
After only a few weeks of working with Drupal I've come up with a
I'm revisiting this after a few weeks, because I could never get it to
I have been playing with nservicebus for a few weeks now and since everything
this is my first post, hopefully I'm following the rules! After a few weeks
A few weeks ago, I have read this thread Is < faster than <=?

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.