0

我有一个日历控件,在选择相应的日期时,我需要在手风琴中将 Today's Due 和 Over due 显示为两个部分。我在后面的代码中编写了手风琴的 div,并设置了 style.css 以呈现手风琴的外观。后面代码中的数据被转换成json并显示出来。后面的代码如下:

[WebMethod(EnableSession = true)]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public string CalenderBinderAccordian()
        {
            try
            {
                //Code to fetch productGroup is not shown
                foreach (var p in productGroup)
                {
                    var todoCount = 1;
                    string todoString = "";
                    int uniqueID = Guid.NewGuid().GetHashCode();
                    todoString = "<div class='accordion vertical'><section id='" + uniqueID + "' style='overflow-y: scroll;'> <h2><a href=#" + uniqueID + "><b>Due Today</b></a></h2>";    
                    foreach (var t in p.todo)
                    {
                        var tempAmt = String.Empty;
                        if ((t.Amount == null) || t.Amount == String.Empty)
                            tempAmt = "0";
                        else
                            tempAmt = Convert.ToDecimal(t.Amount.ToString()).ToString();                          
                        todoString += "<p><div style='padding:5px 0px; border-bottom:dashed 1px #dddddd;'><b>" + todoCount.ToString() + "</b>. " + t.ProductName + "<span style='text-align:right; padding-right:5px;'> $" + tempAmt + "</span><a href='www.google.com' target='_blank' style='text-decoration:none;'><b>Pay Now</b></a></div></p>";
                        todoCount++;
                    }
                    todoString += "</section>";   

                    var overDue = temps.Select(x => new { x.DueDate }).Distinct().ToList();
                    int overDueCount = 0;
                    uniqueID = Guid.NewGuid().GetHashCode();
                    todoString += "<section id='" + uniqueID + "'> <h2><a href=#" + uniqueID + "><b>Over Due</b></a></h2>";
                    int todoCount1 = 1;
                    for (int i = 0; i < overDue.Count(); i++)
                    {

                        if ((Convert.ToDateTime(overDue[i].DueDate) - Convert.ToDateTime(p.dates)).Days < 0)
                        {
                            overDueCount++;

                            var overDueList = temps.FindAll(x => x.DueDate.Equals(overDue[i].DueDate)).ToList();
                            foreach (var t in overDueList)
                            {
                                var tempAmt = String.Empty;
                                if ((t.Amount == null) || t.Amount == String.Empty)
                                    tempAmt = "0";
                                else
                                    tempAmt = Convert.ToDecimal(t.Amount.ToString()).ToString();
      //Error occurs when the href is given as aspx                                                           
                                todoString += "<p><div style='padding:5px 0px; border-bottom:dashed 1px #dddddd;'><b>" + todoCount1.ToString() + "</b>. " + t.ProductName + "<span style='text-align:right; padding-right:5px;'> $" + tempAmt + "</span><a href='PaymentDetails.aspx' target='_blank' style='text-decoration:none;'><b>Pay Now</b></a></div></p>";
                                todoCount++;
                                todoCount1++;
                            }

                        }
                    }

                    todoString = todoString + "</section></div>\",\"count\":\"" + todoCount + "\"},";
                    jsonString = jsonString + String.Format("{{\"{0}\" : \"{1}\",\"{2}\" : \"{3}", "dates", p.dates, "todo", todoString);

                    if (overDueCount.Equals(0))
                    {
                        jsonString = jsonString.Replace("</section><section id='" + uniqueID + "'> <h2><a href=#" + uniqueID + "><b>Over Due</b></a></h2></section>", "</section>");
                    }  

                }
                jsonString = jsonString.TrimEnd(',');
                jsonString = '[' + jsonString + ']';
               string data= jsonString; JavaScriptSerializer().Serialize(productGroup);
                return data;
            }
            catch (Exception ex)
            {
                throw;
            }
        }

//如何将数据转换为Jsonvar tododate = [];

$(window).bind('loaded', function () {
    $.ajax({
        type: "POST",
        url: "ChartBinder.asmx/CalenderBinderAccordian",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {        
            tododate = JSON.parse(msg.d);

        },
        error: function (msg) {
            alert("error");
        }
    });   
});

请注意,当 href 提供为 www.google.com 时,该功能运行良好,但当它提供为 PaymentGateway.aspx 时,它不会以手风琴格式显示日期,而是显示错误警报。

4

1 回答 1

1

使用 Firebug,注意到以下错误:使用 JSON JavaScriptSerializer 进行序列化或反序列化期间出错。字符串的长度超过了 maxJsonLength 属性上设置的值解决方案:尝试更改配置:

<configuration> 
<system.web.extensions>
<scripting>
  <webServices>
    <jsonSerialization maxJsonLength="50000000"/>
  </webServices>
</scripting>

于 2013-01-11T14:06:26.363 回答