Tuesday, 3 September 2013

Calling RenderAction in Controller ASP.NET MVC 4

Calling RenderAction in Controller ASP.NET MVC 4

I have this situation. I have a template HTML string, which at various
unknown points has {{Url}} placeholders in it, which relate to certain
controller/actions in my application. What I need to do is render the
Actions into this string, before rendering the final result in a view.
In a view I can simply call Html.RenderAction("Action","Controller") which
returns the string I need.
However, I need to call this method in the code behind, for example (This
is simplified):
In "Dashboard" Controller:
var templateHtml = GetTemplateHtml();
var html = Html.RenderAction("Index","PowerAnalysisDashpart");
ViewBag.Html = templateHtml.Replace("{{PowerAnalysisDashpart}}",html)
Then in the "Dashboard View":
<div id="content">
@ViewBag.Html
</div>
The problem is I can't call "RenderAction" to get the Rendered HTML string
in the controller.

No comments:

Post a Comment