如何在javascript

时间:2019-02-13 04:15:03

标签: dictionary

我在动作方法中按如下方式将一组字典条目存储在字典值中

[HttpPost]
    public bool ValidateCategory(string value, string category, string attribute, string attrbuteType, int fieldType)
    {
        Structure structure = (Structure)HttpContext.Session["Return-Source-Structure"];
        bool isValid = false;
        string ValidateMessage = "";

        try
        {
            Category oCategory = new Category();
            oCategory.OrgCode = structure.OrgCode;
            oCategory.SiteCode = structure.SiteCode;
            oCategory.ClientCode = structure.ClientCode;
            oCategory.StructureCode = structure.Code;

            oCategory._Category = category;
            oCategory.FieldCode = attribute;
            switch (fieldType)
            {
                case 1:
                    switch (attrbuteType)
                    {
                        case "DATE":
                            if (value != null)
                            {
                                TimeZone localZone = TimeZone.CurrentTimeZone;

                                DateTime dateTime;
                                try
                                {
                                    //bool daylightTime = localZone.IsDaylightSavingTime(DateTime.ParseExact(value, "ddd MMM dd yyyy HH:mm:ss 'GMT+1100 (Australian Eastern Daylight Time)'", CultureInfo.InvariantCulture));
                                   }
                                    dateTime = DateTime.ParseExact(value, "ddd MMM dd yyyy HH:mm:ss 'GMT+1100 (Australian Eastern Daylight Time)'", CultureInfo.InvariantCulture);
                                    oCategory.Value = dateTime.ToString();
                                }
                                catch
                                {
                                    dateTime = DateTime.ParseExact(value, "ddd MMM dd yyyy HH:mm:ss 'GMT+1000 (Australian Eastern Standard Time)'", CultureInfo.InvariantCulture);
                                    oCategory.Value = dateTime.ToString();
                                }                                   

                            }
                            break;
                        default:
                            oCategory.Value = value;
                            break;
                    }
                    break;
                case 2:
                    oCategory.Value = value;
                    break;

            }               

            CategoryRepository categoryRepository = new CategoryRepository(oCategory);

            if (categoryRepository.ValidateCategory(User.Identity.Name, out ValidateMessage))
            {                    
                isValid = true;
            }
            else
            {
                isValid = false;
            }
        }
        catch (Exception e) { isValid = false; }
        HttpContext.Session["ValidateMessage"] = ValidateMessage;


        dict[attribute] = ValidateMessage;           
        HttpContext.Session["attributeMessageDictionary"] = dict;
        return isValid

我的字典定义在控制器中定义为以下

  private static Dictionary<string, string> dict = new Dictionary<string, string>();

动作方法返回的词典进入会话:

我的会话操作方法

    [HttpGet]
    public Dictionary<string,string> getDictionaryObjet(string key)
    {
        return (Dictionary<string, string>)Session[key];
    }

退回退货有困难     使用Javascript代码的System.Collections.Generic.KeyValuePair。我通过上面的动作方法通过Ajax方法检索了此结果,结果得到了如图所示的数据。

以上是我在VS调试器监视窗口中的结果,我需要使用Javascript检索字典中所有值。

0 个答案:

没有答案