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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:10:27+00:00 2026-05-30T02:10:27+00:00

I’ve asked this question as a comment on another post but couldn’t get it

  • 0

I’ve asked this question as a comment on another post but couldn’t get it to work. I’m using RenderRazorViewToString() method, but somehow the JSON that get returned got all the Visual studio formatting with it (tabs, white spaces, line-breaks, etc…), here’s what I’ve done:

public virtual ActionResult RenderToString()
{
    var html = RenderRazorViewToString(MVC.Markets.Views._RenderToString);
    return Json(new { html = html }, JsonRequestBehavior.AllowGet);
}

Here’s the result that got returned:

{"html": "<div class=\"frame company-quote contain\" data-module-name=\"FirstGlanceModule\">\r\n\t<div data-module-name=\"CompanyHeaderModule\">\r\n\t\t<h1>\r\n\t\t\tMicrosoft Corp <em>(MSFT:NASDAQ)</em></h1>\r\n\t</div>\r\n\t<div class=\"first-glance\" data-module-name=\"FirstGlanceQuoteModule\">\r\n\t\t<table>\r\n\t\t\t<thead>\r\n\t\t\t\t<tr>\r\n\t\t\t\t\t<th>\r\n\t\t\t\t\t\tPrice\r\n\t\t\t\t\t</th>\r\n\t\t\t\t\t<th>\r\n\t\t\t\t\t\tChange\r\n\t\t\t\t\t</th>\r\n\t\t\t\t\t<th>\r\n\t\t\t\t\t\tVolume\r\n\t\t\t\t\t</th>\r\n\t\t\t\t\t<th>\r\n\t\t\t\t\t\tMarket Cap\r\n\t\t\t\t\t</th>\r\n\t\t\t\t</tr>\r\n\t\t\t</thead>\r\n\t\t\t<tbody>\r\n\t\t\t\t<tr>\r\n\t\t\t\t\t<td>\r\n\t\t\t\t\t\t$30.13\r\n\t\t\t\t\t</td>\r\n\t\t\t\t\t<td>\r\n\t\t\t\t\t\t<span class=\"neg\">-0.13</span>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t\t<td>\r\n\t\t\t\t\t\t32.75 M\r\n\t\t\t\t\t</td>\r\n\t\t\t\t\t<td>\r\n\t\t\t\t\t\t$252.77 B\r\n\t\t\t\t\t</td>\r\n\t\t\t\t</tr>\r\n\t\t\t</tbody>\r\n\t\t</table>\r\n\t</div>\r\n\t<div class=\"controls\" data-module-name=\"FirstGlanceControlsModule\">\r\n\t\t<em>Data as of February 15, 2012 01:59:59 PM ET</em>\r\n\t\t<div>\r\n\t\t\t<button class=\"type-1\">\r\n\t\t\t\t<span>Add to Watchlist</span></button>\r\n\t\t\t<button class=\"type-2\">\r\n\t\t\t\t<span>Trade</span></button>\r\n\t\t</div>\r\n\t</div>\r\n</div>\r\n"}

I’ve tried to add an extension method outlined here to reformat this into xml with Formatting.None and got a slightly better result, but still have extra tags as well as the xml version tag which I probably don’t want:

{"html": "<?xml version=\"1.0\" encoding=\"utf-16\"?><div class=\"frame company-quote contain\" data-module-name=\"FirstGlanceModule\"><div data-module-name=\"CompanyHeaderModule\"><h1>\r\n\t\t\tMicrosoft Corp <em>(MSFT:NASDAQ)</em></h1></div><div class=\"first-glance\" data-module-name=\"FirstGlanceQuoteModule\"><table><thead><tr><th>\r\n\t\t\t\t\t\tPrice\r\n\t\t\t\t\t</th><th>\r\n\t\t\t\t\t\tChange\r\n\t\t\t\t\t</th><th>\r\n\t\t\t\t\t\tVolume\r\n\t\t\t\t\t</th><th>\r\n\t\t\t\t\t\tMarket Cap\r\n\t\t\t\t\t</th></tr></thead><tbody><tr><td>\r\n\t\t\t\t\t\t$30.13\r\n\t\t\t\t\t</td><td><span class=\"neg\">-0.13</span></td><td>\r\n\t\t\t\t\t\t32.75 M\r\n\t\t\t\t\t</td><td>\r\n\t\t\t\t\t\t$252.77 B\r\n\t\t\t\t\t</td></tr></tbody></table></div><div class=\"controls\" data-module-name=\"FirstGlanceControlsModule\"><em>Data as of February 15, 2012 01:59:59 PM ET</em><div><button class=\"type-1\"><span>Add to Watchlist</span></button><button class=\"type-2\"><span>Trade</span></button></div></div></div>"}

Any idea on how to make this work? 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-05-30T02:10:28+00:00Added an answer on May 30, 2026 at 2:10 am

    Based on this SO question, it looks like there are issues with string.Replace and large strings, since they’re immutable, but StringBuilder should work well even on large strings.

    public virtual ActionResult RenderToString()
    {
        string html = RenderRazorViewToString(MVC.Markets.Views._RenderToString);
        html = new StringBuilder(html)
            .Replace("\n","")
            .Replace("\r","")
            .Replace("\t","")
            .ToString();
        return Json(new { html = html }, JsonRequestBehavior.AllowGet);
    }
    

    Add any other whitespace characters as needed.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into

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.