c# - Rendering an html string to view -
i have 2 controller actions target same view. is, have specified view name on call view controller action. second action puts html string in viewbag. want display html string in view. have tried
@viewbag.htmldoc
and
@html.raw(viewbag.htmldoc)
but nothing rendered.
any appreciated. in advance.
--controller code---
public actionresult showreport(string url) { string tablestring = ""; [code create table called reporttable , add rows etc] tablestring = rendercontroltostring(reporttable ); viewbag.table= tablestring; return view("showreport"); }
i debugged viewbag.table on view , can see html string. view never gets updated / rendered. tested simple text like:
@if (viewbag.table != null) { //@viewbag.table; @:the day is: @datetime.now.dayofweek. }
it goes code know viewbag.table not null, string doesn't rendered, either.
do need refresh renderbody() in _layout.cshtml??? or effect?
-- ajax call--
a button onclick event calls ajax method:
$.ajax({ url: "/home/showreport", data: { url: urlstring} , type: 'post', success: function(data) { alert(data); }, error: function (e, textstatus, jqxhr) { alert(e.statustext); } });
change action method return json content
public actionresult showreport(string url) { string tablestring = ""; [code create table called reporttable , add rows etc] tablestring = rendercontroltostring(reporttable ); //viewbag.table= tablestring; return this.content(tablestring, "application/json"); }
alter jquery reutilize return value
success: function(data) { $('#divtable').innerhtml(data);
and add div view want render html
<div id='divtable'></div>
Comments
Post a Comment