当前位置: 首页>>代码示例>>C#>>正文


C# ViewDataDictionary.AnyWithNullCheck方法代码示例

本文整理汇总了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();
            }
        }
开发者ID:dibiancoj,项目名称:ToracLibrary,代码行数:37,代码来源:RazorToString.cs


注:本文中的ViewDataDictionary.AnyWithNullCheck方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。