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


C# ViewDataDictionary.ContainsKey方法代码示例

本文整理汇总了C#中ViewDataDictionary.ContainsKey方法的典型用法代码示例。如果您正苦于以下问题:C# ViewDataDictionary.ContainsKey方法的具体用法?C# ViewDataDictionary.ContainsKey怎么用?C# ViewDataDictionary.ContainsKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ViewDataDictionary的用法示例。


在下文中一共展示了ViewDataDictionary.ContainsKey方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WriteLog

        public static void WriteLog(ControllerContext controllerContext, ViewDataDictionary viewData)
        {
            var cc = controllerContext.Controller.ControllerContext;

            var category = GetCategory(controllerContext);
            var title = GetTitle(controllerContext);

            var log = new ActionLog
            {
                Controller = cc.RouteData.GetRequiredString("controller"),
                Action = cc.RouteData.GetRequiredString("action"),
                Url = controllerContext.HttpContext.Request.Path,
                CreatedAt = DateTime.Now,
                CreatedBy = "SYSTEM",
                Address = controllerContext.HttpContext.Request.UserHostAddress,
                Actor = TryGetUserName(controllerContext),
                Method = controllerContext.HttpContext.Request.HttpMethod,
                Category = GetCategory(controllerContext),
                Title = title.Equals(category) ? "查询" : title,
                Result = TryGetResult(controllerContext),
                ModelId = cc.RouteData.Values.ContainsKey("id") ? cc.RouteData.GetRequiredString("id") : null,
                Description = viewData.ContainsKey(Const.ToLogMessage) ? viewData[Const.ToLogMessage].ToString() : null
            };

            if (log.Description == null && viewData.ContainsKey(Const.ToLogModel))
            {
                // 取得描述
                var model = viewData.ContainsKey(Const.ToLogModel) ? viewData[Const.ToLogModel] : viewData.Model;
                if (model != null)
                {
                    if (!model.GetType().IsGenericType)
                    {
                        log.Description = model.Print();
                    }
                    else
                    {
                        var objs = (IEnumerable<object>)model;
                        log.Description = string.Join(";" + Environment.NewLine, objs.Select(m => m.Print()));
                    }

                }
            }

            using (var ds = new SessionFactory().OpenSession())
            {
                if (!ds.Create(log))
                {
                    Log.Error("记录日志失败:{0}", log.ToString());
                }
            }
        }
开发者ID:dalinhuang,项目名称:info_platform_i,代码行数:51,代码来源:LogService.cs

示例2: CarregarDadosUsuario

        public static void CarregarDadosUsuario(ViewDataDictionary viewData, bool logado, string tipoUsuario, string erroLogin)
        {
            if (viewData.ContainsKey("logado"))
                viewData["logado"] = viewData["logado"];
            else
                viewData.Add("logado", logado);

            if (viewData.ContainsKey("tipoUsuario"))
                viewData["tipoUsuario"] = viewData["tipoUsuario"];
            else
                viewData.Add("tipoUsuario", tipoUsuario);

            if (viewData.ContainsKey("erroLogin"))
                viewData["erroLogin"] = viewData["erroLogin"];
            else
                viewData.Add("erroLogin", erroLogin);
        }
开发者ID:BernardoMorais,项目名称:LivrariaTDD,代码行数:17,代码来源:Helpers.cs

示例3: RenderPartialWithData

 /// <summary>
 /// Loads the supplied object to the view data dictionary for use by other partials
 /// </summary>
 public static void RenderPartialWithData(this HtmlHelper htmlHelper, string partialName, string key, object objectToLoad, ViewDataDictionary viewDataDictionary)
 {
     if (!viewDataDictionary.ContainsKey(key))
     {
         viewDataDictionary.Add(key, objectToLoad);
     }
     htmlHelper.RenderPartial(partialName);
 }
开发者ID:cerikpete,项目名称:MVCommand,代码行数:11,代码来源:HtmlExtensions.cs

示例4: GetMatch

 protected virtual string GetMatch(Match m, ViewDataDictionary viewDataDictionary)
 {
     if (m.Success) {
         string key = m.Result("$1");
         if (viewDataDictionary.ContainsKey(key)) {
             return viewDataDictionary[key].ToString();
         }
     }
     return string.Empty;
 }
开发者ID:minhajuddin,项目名称:playground,代码行数:10,代码来源:SimpleView.cs

示例5: Merge

        public void Merge(ViewDataDictionary source, ViewDataDictionary destiny)
        {
            Check.Arguments.ThrowIfNull(source, "source");
            Check.Arguments.ThrowIfNull(destiny, "destiny");

            foreach (var entry in destiny)
                if (!source.ContainsKey(entry.Key))
                    source.Add(entry.Key, entry.Value);

            if (destiny.Model != null)
                source.Model = destiny.Model;
        }
开发者ID:fmanoellima,项目名称:ControleFinanceiro,代码行数:12,代码来源:ViewDataDictionaryHelper.cs

示例6: GetMatch

 protected virtual string GetMatch(Match m, ViewDataDictionary viewData)
 {
     if (m.Success)
     {
         // 获取匹配后的结果,即 ViewData 中的 key 值,并根据这个 key 值返回 ViewData 中对应的 value
         string key = m.Result("$1");
         if (viewData.ContainsKey(key))
         {
             return viewData[key].ToString();
         }
     }
     return string.Empty;
 }
开发者ID:iraychen,项目名称:LCLFramework,代码行数:13,代码来源:HtmlView.cs

示例7: ContentAreaItemContext

        public ContentAreaItemContext(ViewDataDictionary viewData, ContentAreaItem contentAreaItem)
        {
            _viewData = viewData;
            var displayOption = contentAreaItem.LoadDisplayOption() ?? new DisplayOption
                                                                       {
                                                                           Id = Guid.NewGuid().ToString(),
                                                                           Name = "Unknown"
                                                                       };

            if (!_viewData.ContainsKey(Constants.CurrentDisplayOptionKey))
            {
                _viewData.Add(Constants.CurrentDisplayOptionKey, displayOption);
            }
            else
            {
                _viewData[Constants.CurrentDisplayOptionKey] = displayOption;
            }
        }
开发者ID:valdisiljuconoks,项目名称:EPiBootstrapArea,代码行数:18,代码来源:ContentAreaItemContext.cs

示例8: GetFieldValueFromViewData

 private object GetFieldValueFromViewData(ViewDataDictionary viewData, string fieldName)
 {
     object value = null;
     string viewDataKey = null;
     fieldName = ParseFieldName(fieldName, out viewDataKey);
     if (string.IsNullOrEmpty(viewDataKey))
     {
         if (viewData.ContainsKey(fieldName))
         {
             value = viewData[fieldName];
         }
         if (value == null && viewData.Model != null)
         {
             value = GetFieldValueFromObject(viewData.Model, fieldName);
         }
         if (value == null)
         {
             foreach (var item in viewData.Values)
             {
                 value = GetFieldValueFromObject(item, fieldName);
                 if (value != null)
                 {
                     break;
                 }
             }
         }
     }
     else
     {
         if (viewData.ContainsKey(viewDataKey))
         {
             value = GetFieldValueFromObject(viewData[viewDataKey], fieldName);
         }
     }
     return value;
 }
开发者ID:eyouyou,项目名称:Bsc,代码行数:36,代码来源:PageSettingValueProvider.cs

示例9: ViewSingle

        /// <summary>
        /// Renders a single pattern page
        /// </summary>
        /// <param name="id">The dash delimited path of the pattern (e.g. atoms-colors)</param>
        /// <param name="masterName">The optional master view to use when rendering</param>
        /// <param name="parse">Whether or not to parse the template and replace Mustache tags with data</param>
        /// <param name="enableCss">Generate CSS for each pattern. Currently unsupported</param>
        /// <param name="noCache">Set the cacheBuster value to 0</param>
        /// <returns>A pattern page</returns>
        public ActionResult ViewSingle(string id, string masterName, bool? parse, bool? enableCss, bool? noCache)
        {
            // Get data from provider and set additional variables
            var model = new ViewDataDictionary(Provider.Data())
            {
                {"cssEnabled", (enableCss.HasValue && enableCss.Value).ToString().ToLower()},
                {"cacheBuster", noCache.HasValue && noCache.Value ? "0" : Provider.CacheBuster()}
            };

            // Find pattern from dash delimited path
            var pattern = Provider.Patterns()
                .FirstOrDefault(p => p.PathDash.Equals(id, StringComparison.InvariantCultureIgnoreCase));

            if (pattern == null) return null;

            var childLineages = new List<object>();
            var parentLineages = new List<object>();

            // Gather a list of child patterns that the current pattern's template references
            foreach (var childPattern in pattern.Lineages.Select(partial => Provider.Patterns().FirstOrDefault(
                p => p.Partial.Equals(partial, StringComparison.InvariantCultureIgnoreCase)))
                .Where(childPattern => childPattern != null))
            {
                childLineages.Add(new
                {
                    lineagePath =
                        string.Format("../../{0}/{1}",
                            PatternProvider.FolderNamePattern.TrimStart(PatternProvider.IdentifierHidden),
                            childPattern.HtmlUrl),
                    lineagePattern = childPattern.Partial,
                    lineageState = PatternProvider.GetState(childPattern)
                });
            }

            // Gather a list of parent patterns whose templates references the current pattern
            var parentPatterns = Provider.Patterns().Where(p => p.Lineages.Contains(pattern.Partial));
            foreach (var parentPattern in parentPatterns)
            {
                parentLineages.Add(new
                {
                    lineagePath =
                        string.Format("../../{0}/{1}",
                            PatternProvider.FolderNamePattern.TrimStart(PatternProvider.IdentifierHidden),
                            parentPattern.HtmlUrl),
                    lineagePattern = parentPattern.Partial,
                    lineageState = PatternProvider.GetState(parentPattern)
                });
            }

            var serializer = new JavaScriptSerializer();

            // Add pattern specific data to the data collection
            model.Add("viewSingle", true);
            model.Add("patternPartial", pattern.Partial);
            model.Add("lineage", serializer.Serialize(childLineages));
            model.Add("lineageR", serializer.Serialize(parentLineages));
            model.Add("patternState", PatternProvider.GetState(pattern));

            // For all values in the pattern data collection update the main data collection
            foreach (var data in pattern.Data)
            {
                if (model.ContainsKey(data.Key))
                {
                    model[data.Key] = data.Value;
                }
                else
                {
                    model.Add(data.Key, data.Value);
                }
            }

            if (!string.IsNullOrEmpty(masterName))
            {
                // If a master has been specified, render 'pattern.html' using master view
                return View(pattern.ViewUrl, masterName, model);
            }

            var html = pattern.Html;

            if (parse.HasValue && parse.Value)
            {
                // If not parsing, render 'pattern.mustache'
                html = Render.StringToString(html, model, new MustacheTemplateLocator().GetTemplate);
            }

            // Else, render 'pattern.escaped.html'
            return Content(Server.HtmlEncode(html));
        }
开发者ID:fhchina,项目名称:patternlab-net,代码行数:97,代码来源:PatternLabController.cs

示例10: AppendData

        /// <summary>
        /// Combines two data collections
        /// </summary>
        /// <param name="original">The original data collection</param>
        /// <param name="additional">The additional data</param>
        /// <returns>The combined data collection</returns>
        public static ViewDataDictionary AppendData(ViewDataDictionary original, Dictionary<string, object> additional)
        {
            foreach (var item in additional)
            {
                if (original.ContainsKey(item.Key))
                {
                    // Replace existing items (e.g. pattern specific data overrides provider-level data)
                    original[item.Key] = item.Value;
                }
                else
                {
                    // Add new items
                    original.Add(item.Key, item.Value);
                }
            }

            return original;
        }
开发者ID:fhchina,项目名称:patternlab-net,代码行数:24,代码来源:PatternProvider.cs

示例11: ValidateViewData

 public static void ValidateViewData(ViewDataDictionary expected, ViewDataDictionary actual)
 {
     if (expected == null)
     {
         return;
     }
     ValidateCount(expected.Count, actual.Count, "ViewData");
     foreach(KeyValuePair<string, object> p in expected)
     {
         Validate(true, actual.ContainsKey(p.Key), string.Format("ContainsKey <{0}>",p.Key));
         Validate(p.Value.ToString(), actual[p.Key].ToString(), "Value");
     }
     Console.WriteLine("===========================");
 }
开发者ID:borealwinter,项目名称:simpl,代码行数:14,代码来源:Validation.cs

示例12: Import

        private void Import(IDictionary<string, object> tempData, ViewDataDictionary currentViewData)
        {
            ViewDataDictionary importingViewData = tempData[Key] as ViewDataDictionary;

            if (importingViewData == null)
            {
                return;
            }

            foreach (KeyValuePair<string, object> pair in importingViewData.Where(pair => ReplaceExisting || !currentViewData.ContainsKey(pair.Key)))
            {
                currentViewData[pair.Key] = pair.Value;
            }

            if ((ReplaceExisting || (currentViewData.Model == null)) && (importingViewData.Model != null))
            {
                currentViewData.Model = importingViewData.Model;
            }

            ModelStateDictionary currentModelState = currentViewData.ModelState;

            foreach (KeyValuePair<string, ModelState> pair in importingViewData.ModelState.Where(pair => ReplaceExisting || !currentModelState.ContainsKey(pair.Key)))
            {
                currentModelState[pair.Key] = pair.Value;
            }
        }
开发者ID:nomit007,项目名称:Core,代码行数:26,代码来源:ImportViewDataFromTempDataAttribute.cs


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