【发布时间】:2014-11-08 22:20:20
【问题描述】:
我的情况如下:In MVC3 Razor, how do I get the html of a rendered view inside an action? 但我使用的是 NancyFx。
谁知道,怎么做?
【问题讨论】:
-
附录:gist.github.com/bhameyie/6314781 使用 NancyFx 将视图呈现为字符串的扩展
我的情况如下:In MVC3 Razor, how do I get the html of a rendered view inside an action? 但我使用的是 NancyFx。
谁知道,怎么做?
【问题讨论】:
我想,我找到了答案:
在http://shanemitchell.ca/tag/nancyfx/
在该方法中,html 位于“var content”中。
ViewLocationContext viewLocationContext = new ViewLocationContext()
{
Context = module.Context,
ModuleName = module.GetType().Name,
ModulePath = module.ModulePath
};
var rendered = module.ViewFactory.RenderView(viewName, model, viewLocationContext);
var content = "";
using (var ms = new MemoryStream())
{
rendered.Contents.Invoke(ms);
ms.Seek(0, SeekOrigin.Begin);
using (TextReader reader = new StreamReader(ms))
{
content = reader.ReadToEnd();
}
};
【讨论】: