从IIS运行应用程序时,为什么从存储过程响应为空?

时间:2016-12-13 07:50:29

标签: jquery ajax asp.net-mvc entity-framework asp.net-mvc-4

我进行ajax调用以检索一些数据。我正在使用实体框架和ajax调用导致存储过程,当我从visual studio运行应用程序时,它成功地返回数据。但是当我在IIS中托管我的应用程序时它返回空数据。

以下是ajax电话:

 function GetChartData() {

    var FromDate = $('#FromDateFilter').val();
    var ToDate = $('#ToDateFilter').val();
    var EmailID = $('#hdnEmailID').val();
    var type = $('#hdnSentOrReceived').val();
    var url;

    if (type == 'sent') {
        url = '@Url.Action("getSentMailsCountPerDay", "Home")'
    }
    else {
        url = '@Url.Action("getReceivedMailsCountPerDay", "Home")'
    }

    $.ajax({
        url: url,
        data: { EmailID: EmailID, FromDate: FromDate, ToDate: ToDate },
        type: "POST",
        async: true,
        cache: false,
        error: function (ex) {
            alert(ex.responseText);
        },
        success: function (data) {
            debugger;
            if (data.issucess) {
                if (data.data.length) {
                    //alert('ssd');
                    for (var i = 0; i < data.data.length; i++) {

                        point = [data.data[i].TotalMails];
                        Points.push(point);

                        Day = [data.data[i].Day];
                        days.push(Day);
                    }
                    GenerateChart(Points, days);
                }
                else {
                    alert(data.error);
                    $("#canvas5").hide();
                }
            }
        }
    });
}

这是我称之为实体框架存储过程的控制器代码

 public ActionResult getSentMailsCountPerDay(string EmailID, string FromDate, string ToDate)
    {
        List<MailCountsPerDay> maildetailList = new List<MailCountsPerDay>();
        List<MailDetails> mailList = new List<MailDetails>();
        int cnt = 0;
        MailCountsPerDay existingMail = new MailCountsPerDay();
        try
        {
            BDEntities entities1 = new BDEntities();
            DateTime FilterByFromDate = DateTime.ParseExact(FromDate, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            DateTime FilterByToDate = DateTime.ParseExact(ToDate, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            var Result1 = entities1.spGetSentMailDetails(EmailID, FilterByFromDate, FilterByToDate);
            foreach (var item in Result1)
            {
                MailDetails mail = new MailDetails();
                mail.LogDateTime = TimeConverter(item.Timezone, Convert.ToDateTime(item.DateTime));

                MailCountsPerDay mails = new MailCountsPerDay();

                if (maildetailList.Where(x => x.DaTe.Contains(mail.LogDateTime.ToShortDateString())).Count() > 0)
                {
                    existingMail = maildetailList.Where(x => x.DaTe.Contains(mail.LogDateTime.ToShortDateString())).FirstOrDefault();
                }

                else
                {
                    cnt = 0;
                }

                mails.DaTe = mail.LogDateTime.ToShortDateString();

                mails.Day = mail.LogDateTime.ToShortDateString().Replace("/", "-").Substring(0, mail.LogDateTime.ToShortDateString().LastIndexOf('-'));

                mails.TotalMails = ++cnt;

                if (mails.DaTe != null && cnt == 1)
                    maildetailList.Add(mails);
                else
                {
                    if (existingMail != null)
                        existingMail.TotalMails = mails.TotalMails;
                }
            }


        }
        catch (Exception ex)
        {
            ViewBag.Message = ex.Message;
        }

        return Json(new { issucess = true, data = maildetailList }, JsonRequestBehavior.AllowGet);
    }

最后这是我在SQL中的SP:

select M.*,BD.Country,BD.Timezone from tblMailDetails M,tblBDMailID BD
where M.FromEmailId = @EmailID and 
BD.MailID = @EmailID and 
 M.ToEmailId Not LIKE '%@tatvasoft.com%' and  M.ToEmailId Not LIKE     '%@etatvasoft.com%' and
CAST(M.[DateTime] as DATE) >= CONVERT(date,  @FilterByFromDate) and     CAST(M.[DateTime] as DATE) <= CONVERT(date,  @FilterByToDate)

请尽可能帮助。

0 个答案:

没有答案