Asp.net Implementation of MVC scheduler

Time:2020-11-21

Asp.net Implementation of MVC scheduler

This example uses fullcalendar JS: https://fullcalendar.io/

1. view :


@{ 
  ViewBag.Title = "Index"; 
  Layout = "~/Views/Shared/_Layout.cshtml"; 
} 
 
 
 
 
@section PageContent{ 
  <style> 
    .modal-backdrop { 
      z-index: 9; 
    } 
  </style> 
  <div> 
 
 
    <div id='calendar'> 
 
 
    </div> 
  </div> 
 
 
 
 
  <!--Select Staff--> 
  <div> 
    <!-- Trigger the modal with a button --> 
    <button type="button" data-toggle="modal" data-target="#myModal" style="display: none"></button> 
 
 
    <!-- Modal --> 
    <div role="dialog" style="z-index: 10"> 
      <div> 
        <br /><br /><br /> 
        <!-- Modal content--> 
        <div> 
         @using (Html.BeginForm("AssignTask", "PMPlan", FormMethod.Post, new { @class="form-horizontal", role="form"} )) 
        { 
 
 
            <div> 
              <button type="button" data-dismiss="modal">×</button> 
              <h4>Create PM Task</h4> 
            </div> 
            <div> 
              <div> 
                <label>your field1</label> 
                <div> 
                  field1 
                </div> 
                <label>field2</label> 
                <div> 
                  <div> 
field2 
                  </div> 
                </div> 
              </div> 
              <br/> 
              <div> 
               ... more rows of fields 
              </div> 
               
              
 
 
            </div> 
            <div> 
              <button type="button" data-dismiss="modal">Close</button> 
              <button type="submit">Submit</button> 
            </div> 
          } 
        </div> 
 
 
      </div> 
    </div> 
 
 
  </div> 
 
 
} 
 
 
@section scripts{ 
  <link href="~/assets3/global/plugins/fullcalendar/fullcalendar.css" rel="external nofollow" rel="stylesheet" /> 
  <script src="~/assets3/global/plugins/fullcalendar/fullcalendar.js"></script> 
 
 
 
 
  <script> 
 
 
    $.get("JsonURL", function (data) { 
 
 
      console.log(JSON.stringify(data)); 
      $('#calendar').fullCalendar({ 
        header: { 
          left: 'prev,next today', 
          center: 'title', 
          right: 'month,basicWeek,basicDay' 
        }, 
        navLinks: false, // can click day/week names to navigate views 
        editable: false, 
        eventLimit: false, // allow "more" link when too many events 
        events: data, 
        dayClick: function () { 
          var dt = $(this).attr("data-date"); 
          $("#hdnAssignedDate").val(dt); 
          //// pop up modal  
          $("#btnSelectStaff").click(); 
        } 
      }); 
    }); 
 
 
 
 
  </script> 
} 

2. Web api controller :


... 
 
 
 public ActionResult GetJsonData() 
    { 
      ... 
      var tasks = //...logic of getting tasks 
    ... 
 
 
      var jsonObjs = tasks.Select(x => new FullCalendaRecord() 
      { 
        title = x.Subject, 
        url = "the url", 
        start = ..., 
        end = x.TargetDate.Value.ToString("yyyy-MM-dd"), 
      }).ToList(); 
 
 
      return Json(jsonObjs, JsonRequestBehavior.AllowGet); 
    } 
 
 
    public class FullCalendaRecord 
    { 
      // sample data: 
      //[ 
      //{ 
      //  title: 'Click for Google', 
      //  url: 'http://google.com/', 
      //  start: '2017-09-28', 
      //  end:'2017-09-28' 
      //} 
      //] 
 
 
      public string title { get; set; } 
      public string url { get; set; } 
      public string start { get; set; } 
      public string end { get; set; } 
    } 
 
 
... 



If you have any questions, please leave a message or go to our community for discussion. Thank you for reading. I hope you can help us. Thank you for your support!