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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:21:10+00:00 2026-06-08T03:21:10+00:00

I build a string that is supposed to be used to generate an HTML

  • 0

I build a string that is supposed to be used to generate an HTML table. I can’t get the text to display as HTML though, it just writes as plain text.

Here’s where I build the string:
StringBuilder HTMLTable = new StringBuilder();

    HTMLTable.AppendLine("<html>");
    HTMLTable.AppendLine("<head>");
    HTMLTable.AppendLine("<style type=\"text/css\">");
    HTMLTable.AppendLine("    .thd {background: rgb(220,220,220); font: bold 10pt Arial; text-align: center;}");
    HTMLTable.AppendLine("    .team {color: white; background: rgb(100,100,100); font: bold 10pt Arial; border-right: solid 2px black;}");
    HTMLTable.AppendLine("    .winner {color: white; background: rgb(60,60,60); font: bold 10pt Arial;}");
    HTMLTable.AppendLine("    .vs {font: bold 7pt Arial; border-right: solid 2px black;}");
    HTMLTable.AppendLine("    td, th {padding: 3px 15px; border-right: dotted 2px rgb(200,200,200); text-align: right;}");
    HTMLTable.AppendLine("    h1 {font: bold 14pt Arial; margin-top: 24pt;}");
    HTMLTable.AppendLine("</style>");
    HTMLTable.AppendLine("</head>");
    HTMLTable.AppendLine("</html>");

    HTMLTable.AppendLine("<body>");
    HTMLTable.AppendLine("<h1>Tournament Results</h1>");
    HTMLTable.AppendLine("<table border=\"0\" cellspacing=\"0\">");
    for (int row = 0; row <= max_rows; row++)
    {
        cumulative_matches = 0;
        HTMLTable.AppendLine("    <tr>");

// etc. etc.

And then I add this string to the viewbag associated with my .cshtml file. I’ve tried things like:

 <text>@ViewBag.bracketHTML</text>

but that doesn’t work. Any ideas?

  • 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-08T03:21:11+00:00Added an answer on June 8, 2026 at 3:21 am

    First, you should take @Zhihao’s suggestion and fix the HTML end tag.

    After that, this should work for you:

    First, set the value of the HTML using the builder’s ToString() function to a property of the ViewBag in the controller:

    var builder = new StringBuilder();
    builder.AppendLine("<div>");
    builder.AppendLine("Testing 123");
    builder.AppendLine("</div>");
    
    ViewBag.testing = builder.ToString();
    

    Next, print it out using Html.Raw():

    @Html.Raw(ViewBag.testing)
    

    Seems to work well!

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

Sidebar

Related Questions

I have a custom class that I use to build table strings. I would
I'm trying to build up a string array in JavaScript and get the results
I'm attempting to build a method call from strings that have been passed into
I have a function that builds substrings given a string recursively. Could anyone please
I'm writing a PHP script that builds an SQL query by concatenating the string
I currently have built a system that checks user IP, browser, and a random-string
I want to loop through the checkboxgroup 'locationthemes' and build a string with all
Consider the following method, where I build a string and return it. I would
When building XML in PHP, is it quicker to build a string, then echo
I have built a Custom Control Class that makes it much easier to build

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.