Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在NancyFx Razor中,如何在动作中获取渲染视图的html?_Razor_Nancy - Fatal编程技术网

在NancyFx Razor中,如何在动作中获取渲染视图的html?

在NancyFx Razor中,如何在动作中获取渲染视图的html?,razor,nancy,Razor,Nancy,我有这样的案例:但我用的是NancyFx 有人知道怎么做吗?我想,我发现answare: 在 在该方法中,html位于“var content”中 附录:使用NancyFx将视图渲染为字符串的扩展 ViewLocationContext viewLocationContext = new ViewLocationContext() { Context = module.Context, ModuleName = module.Ge

我有这样的案例:但我用的是NancyFx


有人知道怎么做吗?

我想,我发现answare:

在该方法中,html位于“var content”中

附录:使用NancyFx将视图渲染为字符串的扩展
 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();
            }
        };