本文整理汇总了C#中ViewLocationResult.Contents方法的典型用法代码示例。如果您正苦于以下问题:C# ViewLocationResult.Contents方法的具体用法?C# ViewLocationResult.Contents怎么用?C# ViewLocationResult.Contents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ViewLocationResult
的用法示例。
在下文中一共展示了ViewLocationResult.Contents方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConvertMarkdown
/// <summary>
/// Converts the markdown.
/// </summary>
/// <returns>
/// HTML converted from markdown
/// </returns>
/// <param name='viewLocationResult'>
/// View location result.
/// </param>
public string ConvertMarkdown(ViewLocationResult viewLocationResult)
{
string content =
viewLocationResult.Contents().ReadToEnd();
if (content.StartsWith("<!DOCTYPE html>"))
{
return MarkdownViewengineRender.RenderMasterPage(content);
}
var parser = new Markdown();
var html = parser.Transform(content);
return ParagraphSubstitution.Replace(html, "$1");
}
示例2: RenderView
/// <summary>
/// Renders the view.
/// </summary>
/// <param name="viewLocationResult">A <see cref="ViewLocationResult"/> instance, containing information on how to get the view template.</param>
/// <param name="model">The model to be passed into the view</param>
/// <param name="renderContext"></param>
/// <returns>A response</returns>
public Response RenderView(ViewLocationResult viewLocationResult, dynamic model, IRenderContext renderContext)
{
return new HtmlResponse
{
Contents = stream =>
{
var templateName = viewLocationResult.Name;
var handlebars = threadLocalHandlebars.Value;
handlebars.RegisterTemplate(templateName, () =>
{
using (var textReader = viewLocationResult.Contents())
{
return textReader.ReadToEnd();
}
});
foreach (var partial in viewLocator.GetAllCurrentlyDiscoveredViews().Where(x => x.Name.StartsWith("_")))
{
var partialName = partial.Name.TrimStart('_');
handlebars.RegisterPartial(partialName, () =>
{
using (var textReader = partial.Contents())
{
return textReader.ReadToEnd();
}
});
}
using (var writer = new StreamWriter(stream))
{
dynamic output;
try
{
output = handlebars.Transform(templateName, model);
}
catch (Exception)
{
//TODO: remove this exception handling after a few versions
var templateContents = viewLocationResult.Contents().ReadToEnd();
if (templateContents.Contains("{{> _") || templateContents.Contains("{{>_"))
{
throw new Exception(string.Format("Template '{0}' contains and underscore prefixed partial name. This is no longer required. Search for the string '{{>_' or '{{> _' in your template and remove the '_'.", templateName));
}
throw;
}
writer.Write(output);
}
}
};
}