本文整理汇总了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());
}
}
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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));
}
示例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;
}
示例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("===========================");
}
示例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;
}
}