在我的mvc完整日历中,事件未显示

时间:2017-03-22 07:17:12

标签: model-view-controller fullcalendar

我在从SQL Server数据库呈现事件时遇到问题。所有事件都是使用此代码获取但未显示在我的日历中,所以有人可以帮助我吗?

.cshtml代码:

 events: function(start, end, callback) {
                debugger;
                 var startdate=start.format('DD-MM-YYYY HH:mm'),
                     enddate=end.format('DD-MM-YYYY HH:mm'),
                     params={'start_time':startdate,'end_time':enddate};
                 $.ajax({

                type: 'GET',

                url: '@Url.Action("GetAllEvents","Base")',

                success: function (data) {
                        alert("hello");
                        }
            });
            }
            ,

我的控制器代码:

public static List<Task_has_UsersModel> LoadAllTasks(double start, double end)
    {
        var fromDate = ConvertFromUnixTimestamp(start);
        var toDate = ConvertFromUnixTimestamp(end);

        var sql = "SELECT * from task_has_users"; 
        var data = Database.Open("DefaultConnection").Query(sql);
        List<Task_has_UsersModel> result = new List<Task_has_UsersModel>(); 
        foreach (var item in data)
        {
            Task_has_UsersModel model = new Task_has_UsersModel();
            model.Task_Id = Convert.ToInt32(item.Task_Id);
            model.Project_Id = Convert.ToInt32(item.Project_Id);
            model.start_time = item.start_time;
            model.end_time = item.end_time;
            result.Add(model);
        }
        return result;
    }
    [HttpPost]
    public JsonResult GetAllEvents(double start, double end)
    {
        var ApptListForDate = LoadAllTasks(start,end);
        var eventList = from e in ApptListForDate
                        select new
                        {
                           id=e.Task_Id,
                           name=e.Project_Id,
                           start=e.start_time.ToString(),
                           end=e.end_time.ToString(),
                           allDay=false,
                           color = "#008000",
                           //allDay=false,
                           className= "label-important" ,
                        };
        var rows = eventList.ToArray();
        return Json(rows, JsonRequestBehavior.AllowGet);
    }



    private static DateTime ConvertFromUnixTimestamp(double timestamp)
        {
            var origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
            return origin.AddSeconds(timestamp);
        }

    }

我尝试过(双重开始,双重结束)仍然没有在日历中显示我的事件

1 个答案:

答案 0 :(得分:0)

经过3天的努力,我完成了这个....不需要在事件中写任何东西,只需调用一个函数,它会自动附加日期范围,你所做的一切...... .............谢谢

.cshtml代码:

events:'GetAllEvents', 


        eventLimit: 50,
        editable: true,
        droppable: true,  

       // timeFormat: 'hh:mm-h:mma ', 
        timeFormat: 'hh:mma ',  
         displayEventEnd : true,  

我的控制器代码:

public static List<Task_has_UsersModel> LoadAllTasks(string start, string       end,string uname)
{

    UsersContext db = new UsersContext(); 

    var uid = (from i in db.UserProfiles
               where i.UserName == uname
               select i.UserId).FirstOrDefault();
    int userId = Convert.ToInt32(uid);
   // var culture = System.Globalization.CultureInfo.CurrentCulture;
    var sql = "SELECT * from task_has_users where UserId = " + userId;  
    var data = Database.Open("DefaultConnection").Query(sql); 

    List<Task_has_UsersModel> result = new List<Task_has_UsersModel>(); 
    foreach (var item in data)
    {
        Task_has_UsersModel model = new Task_has_UsersModel();
        model.Task_Id = Convert.ToInt32(item.Task_Id);
        model.Project_Id = Convert.ToInt32(item.ProjectId);
      //  model.start_time = Convert.ToDateTime(item.start_time);
        model.start_time = (item.start_time).ToString("yyyy-MM-dd HH-mm-ss");
        model.end_time =  (item.end_time).ToString("yyyy-MM-dd HH-mm-ss");
        model.title = item.title;
        result.Add(model);
    }
    return result;
}
[HttpGet]
public JsonResult GetAllEvents(string start, string end)
{
    string uname = (Session["UserName"]).ToString();
    var ApptListForDate = LoadAllTasks(start,end,uname);
    var eventList = from e in ApptListForDate
                    select new
                    {
                       id=e.Task_Id,
                       title=e.title,
                       start=e.start_time,
                       end=e.end_time,
                       allDay=false,
                       color = "#008000",
                       //allDay=false,
                       className= "label-important" ,
                    };
    var rows = eventList.ToArray(); 

    return Json(rows, JsonRequestBehavior.AllowGet);
}

终于完成了