【发布时间】:2018-03-30 08:20:02
【问题描述】:
所以我想构建一个 Html 自定义构建器,它将模型对象传递给局部视图并将页面呈现为 StringWriter
public static class HtmlExtensions
{
public static HtmlString BuildTextboxFor(this IHtmlHelper helper, object model)
{
//Find the partial view and pass the Model through it.
//Render the page into a StringWriter
//return new HtmlString(StringWriter object);
}
}
模型名称将是部分的名称。我似乎找不到 .NET CORE 的解决方案。所有资源似乎都用于 ASP.NET Framework。
【问题讨论】:
-
有什么理由不能使用
@await Html.PartialAsync("PartialName", viewModel)(docs.microsoft.com/en-us/aspnet/core/mvc/views/partial)? -
这可能是另一种方式。有没有办法可以按照上面的方式渲染它?
-
不容易,
HtmlHelper通常只用于剃刀视图的上下文中。如果您正在寻找一种将 Razor 视图呈现为字符串的方法,您可以尝试 github.com/toddams/RazorLight
标签: asp.net-core