为什么用代码写的锚标签的href不接受'aspx'

时间:2013-01-11 13:29:32

标签: c# javascript jquery json

我有一个日历控件并且在选择相应的日期时,我需要在手风琴中显示今天的截止日期和截止日期。我在后面的代码中为手风琴写了div,并设置了style.css来给出Accordion的外观。来自代码的数据被转换为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;
            }
        }

//如何将数据转换为Json var 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给出时,它不会以手风琴格式显示日期,而是显示错误提示。

1 个答案:

答案 0 :(得分:1)

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

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