本文整理汇总了C#中IView.Render方法的典型用法代码示例。如果您正苦于以下问题:C# IView.Render方法的具体用法?C# IView.Render怎么用?C# IView.Render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IView
的用法示例。
在下文中一共展示了IView.Render方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteResultDataToView
public void WriteResultDataToView(IView view)
{
if (_result.Data != null) {
view.Render ("Thank you! Enjoy the book");
}
else {
view.Render ("That book is not available.");
}
}
示例2: InjectViewInPlace
protected IView InjectViewInPlace(string placeholder, IView view, object model)
{
if (placeholder != null)
{
var contentRendering = new ContentRendering()
{
Id = new Guid(),
UniqueId = new Guid(),
Placeholder = placeholder,
DeviceId = PageContext.Current.Device.Id
};
var sw = new StringWriter();
if (model != null) ViewData.Model = model;
var viewConext = new ViewContext(this.ControllerContext, view, ViewData, TempData, sw);
view.Render(viewConext, sw);
contentRendering.Content = sw.ToString();
var currentRenderings = PageContext.Current.PageDefinition.Renderings;
currentRenderings.Add(contentRendering);
}
return PageContext.Current.PageView;
}
示例3: RenderViewAsString
private string RenderViewAsString(ControllerContext context, IView view)
{
using (var writer = new StringWriter())
{
var viewContext = new ViewContext(context, view, ViewData, TempData, writer);
view.Render(viewContext, writer);
string output = writer.GetStringBuilder().ToString();
if (_trimBody)
output = output.Trim();
return output;
}
}
示例4: WriteResultDataToView
public void WriteResultDataToView(IView view)
{
view.Render (_result.Data as string);
}
示例5: RenderView
string RenderView(IView view, ViewDataDictionary viewData, ControllerContext controllerContext)
{
using (var writer = new StringWriter())
{
var viewContext = new ViewContext(controllerContext, view, viewData, new TempDataDictionary(), writer);
view.Render(viewContext, writer);
return writer.GetStringBuilder().ToString();
}
}
示例6: RenderViewToString
/// <summary>
/// Takes a view and renders it into an string representation.
/// </summary>
private string RenderViewToString(ControllerContext context, IView view, object model)
{
if (view == null)
{
return null;
}
StringBuilder sb = new StringBuilder();
using (StringWriter writer = new StringWriter(sb))
{
ViewContext viewContext = new ViewContext(context, view, new ViewDataDictionary(model), new TempDataDictionary(), writer);
view.Render(viewContext, writer);
writer.Flush();
}
string result = sb.ToString();
return result;
}
示例7: WriteResultDataToView
public void WriteResultDataToView(IView view)
{
foreach (Book b in _result.Data as List<Book>) {
view.Render (b.ToString ());
}
}
示例8: CreateSiteHtml
private static async Task<string> CreateSiteHtml(IView view, IPageViewDefinition siteDefinition)
{
var pageHtmlBuilder = new StringBuilder();
using (var writer = new StringWriter(pageHtmlBuilder))
{
var context = new RenderingContext(writer);
context.Data.Add("pageEditor", true);
context.Data.Add("siteDefinition", siteDefinition);
view.Render(JObject.FromObject(siteDefinition), context);
}
var html = pageHtmlBuilder.ToString();
html = html.Replace("<!DOCTYPE html>", "").Replace("<html>", "").Replace("</html>", "");
html = new Regex("<head>(.*)</head>", RegexOptions.Singleline).Replace(html, "");
html = new Regex("<script( src[=]\".*\")?>(.*)</script>", RegexOptions.Singleline).Replace(html, "");
return html;
}
示例9: RenderViewAsString
/// <summary>
/// Render the view as string
/// </summary>
/// <param name="context">current http context</param>
/// <param name="view">valid view</param>
/// <returns></returns>
private string RenderViewAsString(ControllerContext context, IView view)
{
using (StringWriter sw = new StringWriter())
{
var viewContext = new ViewContext(context,view,ViewData,TempData,sw);
view.Render(viewContext, sw);
return sw.GetStringBuilder().ToString();
}
}
示例10: AssertView
protected void AssertView( IView view, string expectedName )
{
Assert.IsNotNull(view, "ViewEngine does not returned a view");
var mockViewContext = new Mock<ViewContext>();
mockViewContext.SetupGet(x => x.View).Returns(view);
mockViewContext.SetupGet(x => x.Controller).Returns(_controllerContext.Controller);
mockViewContext.SetupGet(x => x.HttpContext).Returns(_controllerContext.HttpContext);
mockViewContext.SetupGet(x => x.ViewData).Returns(new ViewDataDictionary());
mockViewContext.SetupGet(x => x.TempData).Returns(new TempDataDictionary());
mockViewContext.SetupGet(x => x.RouteData).Returns(_controllerContext.RouteData);
mockViewContext.SetupGet(x => x.Writer).Returns(Output);
view.Render(mockViewContext.Object, Output);
AssertRender(Output, expectedName);
}
示例11: Respond
public async Task<IHttpResponse> Respond(IHttpContext context, IView view)
{
var output = await view.Render(context, _state).ConfigureAwait(false);
return StringHttpResponse.Create(output.Body, _code, output.ContentType);
}
示例12: RenderView
string RenderView(IView view, ViewDataDictionary viewData, ControllerContext controllerContext, ImageEmbedder imageEmbedder)
{
using (var writer = new StringWriter())
{
var viewContext = new ViewContext(controllerContext, view, viewData, new TempDataDictionary(), writer);
viewData[ImageEmbedder.ViewDataKey] = imageEmbedder;
view.Render(viewContext, writer);
viewData.Remove(ImageEmbedder.ViewDataKey);
return writer.GetStringBuilder().ToString();
}
}
示例13: CaptureHtml
/// <summary>
/// Abstract method to capture and return HTML from the ControllerContext and RazorView
/// </summary>
/// <param name="controllerContext">ControllerContext of the calling Controller - contains ViewData, etc.</param>
/// <param name="view">Instantiated RazorView</param>
/// <returns>HTML</returns>
protected virtual string CaptureHtml(ControllerContext controllerContext, IView view)
{
var builder = new StringBuilder();
using (var stringWriter = new StringWriter(builder))
{
using (var htmlTextWriter = new HtmlTextWriter(stringWriter))
{
// build our view context - we need this to be able to render the view and capture the output
var viewContext = new ViewContext(
controllerContext, // the ControllerContext we are in
view, // the IView object - created by the RazorViewEngine above
GetViewData(controllerContext), // ViewData contains the model - without this model data would not be rendered
GetTempData(controllerContext), // TempData contains the Controller's TempData
htmlTextWriter); // the TextWriter the output is being written to - we control this!
// now render the view - because we own htmlTextWriter, we can now capture all the rendered output
view.Render(viewContext, htmlTextWriter);
// don't forget to flush!
htmlTextWriter.Flush();
stringWriter.Flush();
}
}
return builder.ToString();
}