使用 razorpages entity framework 处理完整日历

Using razorpages entity framework to work with full calendar

我无法让 entity frameworks 数据在具有完整日历的前端工作。我目前有将 entity framework 数据转换为 JSON 结果的程序,但我无法获取日历来访问它。它目前正确显示 UI 但不允许显示任何 jason 结果。我可以提取 json 结果。

后端:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using TeleHealthB.Models;
using Microsoft.AspNetCore.Http;


namespace TeleHealthB.Pages
{
    public class CalenderModel : PageModel
    {
        private TeleHealthB.Models.HealthProjectContext healthProject;

        // public IndexModel(TeleHealthB.Models.HealthProjectContext context)
        //{
        //  healthProject = context;
        //}


        [BindProperty]
        public string Title { get; set; }

        [BindProperty]
        public string Doc { get; set; }
        [BindProperty]
        public string Pat { get; set; }
        [BindProperty]
        public string dec { get; set; }
        [BindProperty]
        public DateTime date { get; set; }

        private Schedule schedule;
        [BindProperty]
        public JsonResult result { get; set; }

        
        public string today = DateTime.Today.ToString();

         public void OnGet()
        {

         result = (JsonResult)OnGetEvents();
        }


       public class eventShow
        {
            public int id { get; set; }
            public string title { get; set; }
            public string description { get; set; }
            public string start { get; set; }
            public string end { get; set; }

            

            //public string description { get; set; }

           // public string patient { get; set; }

         //   public string doctor { get; set; }
            



        }

        private HealthProjectContext db;
        public CalenderModel(HealthProjectContext _db)
        {
            db = _db;
        }
        public IActionResult OnGetEvents()
        {
            List<eventShow> events= new List<eventShow>();
            eventShow show = new eventShow();
            try
            {
                string x = HttpContext.Session.GetString("username");

                using (var context = new HealthProjectContext())
                {

                    var query = from st in db.Schedules
                                where st.Id == 1 //|| st.DoctorEmail == x.Trim()
                                select st;



                    foreach (var item in query.ToList())
                    {

                        show.id = item.Id;
                        show.title = item.Title;
                        show.description = item.Description;
                        show.start = item.Start.ToString("MM/dd/yyyy");
                        show.end = item.End.ToString("MM/dd/yyyy");


                        events.Add(show);
                    }





                    return new JsonResult(events);
                }
```

front end
```
@page

@model TeleHealthB.Pages.CalenderModel
@{



    <!DOCTYPE html>
    <html lang='en'>
    <head>
        <meta charset='utf-8' />
        <link href='~/lib/TestCalender/main.css' rel='stylesheet' />
        <script src='~/lib/TestCalender/main.js'></script>
        <script>

            document.addEventListener('DOMContentLoaded', function () {
                var calendarEl = document.getElementById('calendar');

                var calendar = new FullCalendar.Calendar(calendarEl, {
                    headerToolbar: {
                        left: 'prev,next today',
                        center: 'title',
                        right: 'dayGridMonth,timeGridWeek,timeGridDay'
                    },
                  

                    initialDate: '2020-09-12',
                    navLinks: true, // can click day/week names to navigate views
                    selectable: true,
                    selectMirror: true,
                    select: function (arg) {
                        var title = prompt('Reasining For meeting:');

                        if (title)
                        {
                            var tie = prompt('Time');
                        }

                        if (title) {
                            calendar.addEvent({
                                title: title,
                                start: arg.start,
                                Starttime: tie,
                                end: arg.end,
                                EndTime: arg.EndTime
                            })
                        }
                        calendar.unselect()
                    },
                    eventClick: function (arg) {
                        if (confirm('Are you sure you want to delete this event?')) {


                            arg.event.remove()
                        }
                    },
                    editable: true,
                    dayMaxEvents: true, // allow "more" link when too many events
                    events:$.getJSON('https://localhost:44337/OnGetEvents')
                     
                    
                });

                calendar.render();
            });

        </script>
        <style>

            body {
                margin: 40px 10px;
                padding: 0;
                font-family: Arial, Helvetica Neue, Helvetica, sans-serif;
                font-size: 14px;
            }

            #calendar {
                max-width: 1100px;
                margin: 0 auto;
            }
        </style>
    </head>
    <body>

        <div id='calendar'></div>

    </body>
</html>
    }
```

您只需像下面这样更改您的 Events

 events:"/calender?handler=events"

测试结果: