Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.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/1/asp.net/31.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
C# 从网页获取结果HTML_C#_Asp.net_Asp.net Mvc - Fatal编程技术网

C# 从网页获取结果HTML

C# 从网页获取结果HTML,c#,asp.net,asp.net-mvc,C#,Asp.net,Asp.net Mvc,我有一个System.Web.WebPages.WebPages对象,我用它做了一些事情。 是否有可能从网页中获取结果HTML 我在谷歌上搜索过,但找不到答案。。摘自本博客: protected string RenderPartialViewToString(string viewName, object model) { if (string.IsNullOrEmpty(viewName)) viewName = ControllerContext.RouteData

我有一个System.Web.WebPages.WebPages对象,我用它做了一些事情。 是否有可能从网页中获取结果HTML

我在谷歌上搜索过,但找不到答案。

。摘自本博客:

protected string RenderPartialViewToString(string viewName, object model)
{
    if (string.IsNullOrEmpty(viewName))
        viewName = ControllerContext.RouteData.GetRequiredString("action");

    ViewData.Model = model;

    using (StringWriter sw = new StringWriter()) 
    {
        ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName);
        ViewContext viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);
        viewResult.View.Render(viewContext, sw);

        return sw.GetStringBuilder().ToString();
    }
}
但是,如果您正在尝试我认为您正在尝试的操作(将视图呈现为字符串以便将其作为电子邮件发送),请不要执行我显示的操作,只需使用或

你也可能会发现这个方法很有用