如何在Asp.Net MVC中将DayPilot月历设置为只读?

时间:2019-02-23 18:25:56

标签: asp.net ajax asp.net-mvc calendar daypilot

我的项目中有DayPilot月历,但是我想将其设为只读日历。我找到了一篇有关如何执行此操作的文章,但不确定如何将其添加到我的代码中。有人可以帮助我处理我的代码或提供更多有关执行该操作的链接吗?

我认为本教程是您的工作方式,但我不知道如何将其实现到我的代码中: https://kb.daypilot.org/15969/how-to-make-the-calendar-events-read-only/

我遵循了这两个教程,将DayPilot月历添加到我的ASP.NET MVC项目中。

https://www.codeproject.com/script/Articles/ArticleVersion.aspx?aid=404647&av=1059127&fid=1732162&df=90&mpp=25&prof=True&sort=Position&view=Normal&spc=Relaxed&fr=81

还有一个月 https://code.daypilot.org/10607/monthly-event-calendar-for-asp-net-mvc-and-jquery-open-source

我的代码如下:

 Home Controller
 public class HomeController : Controller
{
    public ActionResult Index()
    {
        return View();
    }

    public ActionResult Backend()
    {
        return new Dpm().CallBack(this);
    }

    class Dpm : DayPilotMonth
    {
        DataClasses1DataContext db = new DataClasses1DataContext();

        protected override void OnInit(InitArgs e)
        {
            Update(CallBackUpdateType.Full);
        }

        protected override void OnEventResize(EventResizeArgs e)
        {
            var toBeResized = (from ev in db.Events where ev.id == Convert.ToInt32(e.Id) select ev).First();
            toBeResized.eventstart = e.NewStart;
            toBeResized.eventend = e.NewEnd;
            db.SubmitChanges();
            Update();
        }

        protected override void OnEventMove(EventMoveArgs e)
        {
            var toBeResized = (from ev in db.Events where ev.id == Convert.ToInt32(e.Id) select ev).First();
            toBeResized.eventstart = e.NewStart;
            toBeResized.eventend = e.NewEnd;
            db.SubmitChanges();
            Update();
        }

        protected override void OnTimeRangeSelected(TimeRangeSelectedArgs e)
        {
            var toBeCreated = new Event { eventstart = e.Start, eventend = e.End, text = (string)e.Data["name"] };
            db.Events.InsertOnSubmit(toBeCreated);
            db.SubmitChanges();
            Update();
        }


        protected override void OnFinish()
        {
            if (UpdateType == CallBackUpdateType.None)
            {
                return;
            }

            Events = from ev in db.Events select ev;

            DataIdField = "id";
            DataTextField = "text";
            DataStartField = "eventstart";
            DataEndField = "eventend";
        }

    }
}

索引页

@{

  ViewBag.Title = "AJAX Monthly Event Calendar for ASP.NET MVC";
 }

<script src="~/Scripts/jquery-1.9.1.min.js" type="text/javascript"></script>
<script src="~/Scripts/daypilot-all.min.js" type="text/javascript"></script>

<div id="dpm"></div>

@Html.DayPilotMonth("dpm", new DayPilotMonthConfig
{
BackendUrl = Url.Content("~/Home/Backend"),

EventMoveHandling = 
DayPilot.Web.Mvc.Events.Month.EventMoveHandlingType.CallBack,
EventResizeHandling = 
DayPilot.Web.Mvc.Events.Month.EventResizeHandlingType.CallBack,
TimeRangeSelectedHandling = 
DayPilot.Web.Mvc.Events.Month.TimeRangeSelectedHandlingType.JavaScript,
TimeRangeSelectedJavaScript =
"dpc.timeRangeSelectedCallBack(start, end, null, { name: prompt('New Event 
Name:', 'New Event') });"
})
<script type="text/javascript">
var dp;

$(document).ready(function() {
dp = $("#dpm").daypilotMonth({
  backendUrl: '@Url.Content("~/Home/Backend")',
  eventMoveHandling: "CallBack",
  eventResizeHandling: "CallBack",
  timeRangeSelectedHandling: "JavaScript",
  onTimeRangeSelected: function(args) { 
  dp.timeRangeSelectedCallBack(args.start, args.end, { name: prompt('New 
  Event Name:', 'New Event') }); }
  });
  });
 </script>

0 个答案:

没有答案