本文整理汇总了C#中ViewDataDictionary.AnyWithNullCheck方法的典型用法代码示例。如果您正苦于以下问题:C# ViewDataDictionary.AnyWithNullCheck方法的具体用法?C# ViewDataDictionary.AnyWithNullCheck怎么用?C# ViewDataDictionary.AnyWithNullCheck使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ViewDataDictionary
的用法示例。
在下文中一共展示了ViewDataDictionary.AnyWithNullCheck方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RenderRazorViewToString
/// <summary>
/// Renders A ViewEngineResult (Either A Partial View Or A View) To A String
/// </summary>
/// <param name="ControllerToRenderWith">Controller to render the view with</param>
/// <param name="RazorViewToRender">Partial view or view to render</param>
/// <param name="Model">Model that gets passed into the view</param>
/// <param name="ViewBagData">View Bag that is accessible when the view is rendered</param>
/// <returns>Rendered partial view as string</returns>
internal static string RenderRazorViewToString(Controller ControllerToRenderWith, ViewEngineResult RazorViewToRender, object Model, ViewDataDictionary ViewBagData)
{
//set the model
ControllerToRenderWith.ViewData.Model = Model;
//make sure the view bag data is not null{
if (ViewBagData.AnyWithNullCheck())
{
//we need to make sure we include both the controller and the view data we pass in...so add the view data to the controllers view data
foreach (KeyValuePair<string, object> thisViewBagItem in ViewBagData)
{
//add the view data to the controller's view data
ControllerToRenderWith.ViewData.Add(thisViewBagItem);
}
}
//create the string write to output the html
using (var ViewStringWriter = new StringWriter())
{
//create the view context with all the view data..and render that control to the view context
var ViewContextToUse = new ViewContext(ControllerToRenderWith.ControllerContext, RazorViewToRender.View, ControllerToRenderWith.ViewData, ControllerToRenderWith.TempData, ViewStringWriter);
//Now go render the partial view to the string writer
RazorViewToRender.View.Render(ViewContextToUse, ViewStringWriter);
//return the string which contains the html for this partial view with the model and view data embedded
return ViewStringWriter.GetStringBuilder().ToString();
}
}