渲染剃刀以字符串没有改写(munging)在html [英] Render razor view to string without munging the html

查看:170
本文介绍了渲染剃刀以字符串没有改写(munging)在html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经previously发现就如何使一个MVC 4视图为一个字符串的答案。不过,我开始使用,现在并不如预期的的Visual Studio 2013的结果。见下文。

I've previously found answers on how to render an MVC 4 view to a string. However, I started using Visual Studio 2013 and now the result is not as expected. See below.

 <$A$><$B$> <$C$> class="panel"<$D$>> <$E$> class="cover-wrapper"<$F$>> <$G$> href="     
 <$H$>/book/<$I$><$J$>1<$K$><$L$>/<$M$>"<$N$>><$O$> src="<$P$>http://www.
 example.com/images/image.jpg<$Q$>"<$R$> class="cover"<$S$> /> <$T$> href="<$U$>
 <$V$>"<$W$> target="_blank"<$X$> rel="nofollow"<$Y$> class="amazon-button"<$Z$>> <$a$> 
 class="amazon-cart"<$b$>> Link → 
 <$c$> class="content"<$d$>>..........

在code使用是这样的:

The code being used is this:

    public string RenderRazorViewToString(string viewName, object model)
    {
        ViewData.Model = model;
        using (var sw = new StringWriter())
        {
            var viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName);
            var viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);
            viewResult.View.Render(viewContext, sw);
            viewResult.ViewEngine.ReleaseView(ControllerContext, viewResult.View);
            return sw.GetStringBuilder().ToString();
        }
    }

任何想法,为什么所有的字母和美元符号现在显示出来或者我需要怎么改变我的code把它给我使用的HTML?

Any idea as to why all the letters and dollar signs are showing up now or how I need to change my code to get it to give me usable html?

推荐答案

这其实是我在暑假期间遇到了一个错误,请参阅微软的错误报告和响应这里<一个href=\"https://connect.microsoft.com/VisualStudio/feedback/details/794142/vs2013-$p$pview-viewengineresult-render-returning-malformed-html\"相对=nofollow>错误和解决方法。好消息是,根据MS VS2013发布时,它应该是固定的。

This is actually a bug I ran into during the summer, see bug report and response from Microsoft here bug and workaround. Good news is that according to MS it should be fixed when VS2013 is released.

解决方法是禁用浏览器链接功能在这里看到的<一个href=\"http://blogs.msdn.com/b/webdev/archive/2013/06/28/browser-link-feature-in-visual-studio-$p$pview-2013.aspx.\"相对=nofollow>浏览器链接功能

Workaround is to disable the browser link feature see here browser link feature

这篇关于渲染剃刀以字符串没有改写(munging)在html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆