我使用以下渲染的局部視圖爲一個字符串...渲染到字符串MVC4局部視圖
protected string RenderPartialViewToString(string viewName, object model)
{
if (string.IsNullOrEmpty(viewName))
viewName = ControllerContext.RouteData.GetRequiredString("action");
ViewData.Model = model;
using (var sw = new StringWriter())
{
ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName);
var viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);
viewResult.View.Render(viewContext, sw);
return sw.GetStringBuilder().ToString();
}
}
但是它返回與這樣的下方奇怪代碼的HTML ...(我已經包括一個小部分作爲一個大視圖)
<$A$><div</$A$><$B$> class="modal hide fade"</$B$><$C$> id="dialog"</$C$><$D$>
這發生在整個HTML。這部分應該看起來像這樣...
<div class="modal hide fade" id="dialog" style="display: none;">
可能重複的[MVC4 - 如何呈現視圖的字符串?](http://stackoverflow.com/questions/17273826/mvc4-how-to-render-a-view-a-string) – SlimShaggy