Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.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
ASP.NET MVC相当于;“覆盖无效渲染”;从ASP.NET WebForms_Asp.net_Asp.net Mvc_Render - Fatal编程技术网

ASP.NET MVC相当于;“覆盖无效渲染”;从ASP.NET WebForms

ASP.NET MVC相当于;“覆盖无效渲染”;从ASP.NET WebForms,asp.net,asp.net-mvc,render,Asp.net,Asp.net Mvc,Render,ASP.NET MVC与ASP.NET WebForms中的“覆盖无效渲染”等效于什么? 在将输出发送到客户机之前,您在哪里有机会进行最后一分钟的处理 例如,我不会在生产代码中使用它,但演示了在WebForms应用程序的母版页中清理整个站点的和标记 protected override void Render(HtmlTextWriter writer) { System.IO.StringWriter sw = new System.IO.StringWrite

ASP.NET MVC与ASP.NET WebForms中的“覆盖无效渲染”等效于什么? 在将输出发送到客户机之前,您在哪里有机会进行最后一分钟的处理

例如,我不会在生产代码中使用它,但演示了在WebForms应用程序的母版页中清理整个站点的
标记

    protected override void Render(HtmlTextWriter writer)
    {
        System.IO.StringWriter sw = new System.IO.StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);
        base.Render(htw);
        htw.Close();
        string h = sw.ToString();
        string fhtml = h.Replace("<title>\r\n\t", "\n<title>")
                             .Replace("\r\n</title>", "</title>")
                             .Replace("</head>","\n</head>");
        // write the new html to the page
        writer.Write(fhtml);
    }
受保护的覆盖无效渲染(HtmlTextWriter)
{
System.IO.StringWriter sw=新的System.IO.StringWriter();
HtmlTextWriter htw=新的HtmlTextWriter(sw);
基础渲染(htw);
htw.Close();
字符串h=sw.ToString();
字符串fhtml=h.Replace(“\r\n\t”,“\n”)
.Replace(“\r\n”,”)
.替换(“,”\n”);
//将新的html写入页面
writer.Write(fhtml);
}
在ASP.NET MVC中使用最终文本呈现的最佳方法是什么

更新:

因此,看看Andrew Hare提到的链接(图表),看起来您可以在视图引擎中执行此操作。你能把东西栓在默认视图引擎上或者改变默认视图引擎的工作方式吗?或者你必须替换整个东西吗

这不是MVC的工作方式

所有“onprerender”代码都在视图中完成。当您将数据从控制器传递到视图时,您应该已经完成了显示整个页面所需的所有处理

唯一的一个小小的例外是,当模型被视图探测时,它仍然可以做一些处理


这可能包括设置partials打开或关闭所需的变量等。

据我所知,在
Render()
-方法中,您要做的唯一一件事是重新排列
部分中的一些标记。这在
MVC
中已经为您正确地完成了,除非您使用某种自制的方式在
母版页中创建
-部分


我建议在
Master
html
标记中直接按照您希望的方式对齐标记,并确保
ViewData[“title”]
或使用内容填充标记的任何内容不以换行开始或结束。

我只是以操作为例。但是,MVC在IDE中发挥得很好,仍然存在一些困难。我在一个项目上做过,只是必须放弃ViewData[“title”]策略的默认“title PlaceHolder”。请参阅上对Jason的评论。既然我放弃了占位符,那么现在就有了令人讨厌的下划线CSS问题——实际上,在ViewMasterPage中,仍然会在标题周围添加额外的空格。好的。我想我解决了这个问题。不确定它是否有其他副作用,但如果您从标记中删除runat和id,这将消失。仍然对视图引擎问题感到好奇。我并不怀疑这是最佳实践,但有时这是必需的。我现在面临IE9重影单元问题,我需要清除tr/td/th元素之间的所有空白来解决这个问题。有两种选择。我要么编辑所有视图,要么将所有内容放在一行,这将使其无法维护。另一个选项是使用正则表达式处理最终的HTML输出。这似乎是在现有业务应用程序上执行此操作的更好方法。这与您的问题非常相似:有人想尝试一下问题的更新部分吗?