本文整理汇总了C#中ViewDataDictionary.Any方法的典型用法代码示例。如果您正苦于以下问题:C# ViewDataDictionary.Any方法的具体用法?C# ViewDataDictionary.Any怎么用?C# ViewDataDictionary.Any使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ViewDataDictionary
的用法示例。
在下文中一共展示了ViewDataDictionary.Any方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WrapArrayWithObject
private static IDictionary<string,object> WrapArrayWithObject(dynamic model, TempDataDictionary tempData, ViewDataDictionary viewDataDictionary)
{
var output = new Dictionary<string, object>();
// We want to avoid sending a JSON array as a response.
// See http://haacked.com/archive/2009/06/25/json-hijacking.aspx
// In cases where our model would be converted to an array,
// we wrap it in an object.
object wrappedModel = (typeof(IEnumerable)).IsInstanceOfType(model) ? new { model } : model;
output["Model"] = wrappedModel;
if (tempData.ContainsKey("alert"))
{
output["FlashAlert"] = tempData["alert"].ToString();
}
if (tempData.ContainsKey("confirm"))
{
output["FlashConfirm"] = tempData["confirm"].ToString();
}
if (viewDataDictionary.Any())
{
output["__view__"] = viewDataDictionary
.ToDictionary(viewDataKeyValuePair => viewDataKeyValuePair.Key,
viewDataKeyValuePair => viewDataKeyValuePair.Value);
}
if (viewDataDictionary.ModelState.Any())
{
var errors = viewDataDictionary.ModelState
.Where(p => p.Value.Errors.Any());
if(errors.Any())
output["Errors"] = errors
.ToDictionary(p => p.Key, p => p.Value.Errors.Select(x => x.ErrorMessage).ToArray());
}
return output;
}