Note that there are some explanatory texts on larger screens.

plurals
  1. PORendering an html string to view
    primarykey
    data
    text
    <p>I have two controller actions that target the same view. That is, I have specified a view name on the call to View from controller action. The second action puts an html string in a ViewBag. I simply just want to display this html string in the view. I have tried </p> <pre><code>@ViewBag.HtmlDoc </code></pre> <p>and </p> <pre><code>@Html.Raw(ViewBag.HtmlDoc) </code></pre> <p>but nothing is rendered. </p> <p>Any help would be appreciated. Thanks in advance.</p> <p>--controller code---</p> <pre><code>public ActionResult ShowReport(string URL) { string tableString = ""; [Code to Create table called ReportTable and add rows etc] tableString = RenderControlToString(ReportTable ); ViewBag.Table= tableString; return View("ShowReport"); } </code></pre> <p>I debugged the ViewBag.Table on the View and can see the html string. But the View never gets updated / rendered. I tested with a simple text like:</p> <pre><code>@if (ViewBag.Table != null) { //@ViewBag.Table; @:The day is: @DateTime.Now.DayOfWeek. } </code></pre> <p>It goes into the code so I know ViewBag.Table is not null, but the string doesn't get rendered, either. </p> <p>Do I need to refresh RenderBody() in the _layout.cshtml??? or something to that effect?</p> <p>-- ajax call--</p> <p>a button onclick event calls this ajax method:</p> <pre><code>$.ajax({ url: "/Home/ShowReport", data: { URL: urlString} , type: 'POST', success: function(data) { alert(data); }, error: function (e, textStatus, jqXHR) { alert(e.statusText); } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload