2011-05-17 109 views
1

我試圖在代碼中呈現強類型的視圖頁並獲取生成的HTML輸出。下面是我使用的代碼:在代碼中呈現MVC視圖

public static string RenderPartialToString(ViewPage vp) { 
    StringBuilder sb = new StringBuilder(); 
    using (StringWriter sw = new StringWriter(sb)) { 
     using (HtmlTextWriter tw = new HtmlTextWriter(sw)) { 
      ViewContext vc = new ViewContext(); 
      vc.ViewData = vp.ViewData; 
      vp.RenderView(vc); 
     } 
    } 
    vp.Dispose(); 
    vp = null; 

    string s = sb.ToString(); 
    sb = null; 

    return s; 
} 

現在,我在vp.RenderView()線得到一個MethodNotImplemented錯誤。目前無法呈現MVC視圖頁(MVC 3)嗎?

回答