简体   繁体   English

ASP.Net Core 中的日历

[英]Calendar in ASP.Net Core

Please let me know if this question is posted in the wrong place of Stack - I will make sure to delete this and re-write a new post in the correct place.如果这个问题发布在 Stack 的错误位置,请让我知道 - 我会确保删除它并在正确的位置重新写一篇新帖子。 As of now, I saw similar questions around here and deemed this acceptable as well.截至目前,我在这里看到了类似的问题,并认为这也可以接受。

So, I am wondering what should I use in order to create a view with a calendar on the whole page that has dates highlighted depending on the database dates.所以,我想知道我应该使用什么来在整个页面上创建一个带有日历的视图,该视图根据数据库日期突出显示日期。 For example, in the database, I have the following table:例如,在数据库中,我有下表:

在此处输入图片说明

Therefore, as I said - in the calendar view, there should be a huge calendar with the StartDate and EndDate highlighted with certain colors, also stating the Name of the Release.因此,正如我所说 - 在日历视图中,应该有一个巨大的日历,其中StartDateEndDate用某些颜色突出显示,还说明了发布的Name

How could this be possible?这怎么可能? I am pretty new to this stuff so I am looking for some hints on how I should approach this issue.我对这个东西很陌生,所以我正在寻找一些关于我应该如何处理这个问题的提示。

Thanks a lot!非常感谢!

It think you posted this at the proper spot.它认为你把这个贴在了正确的地方。 Your tags look great.你的标签看起来很棒。

If you are familiar with JavaScript and ASP.Net Core Web APIs I would recommend Full Calendar .如果您熟悉 JavaScript 和 ASP.Net Core Web API,我会推荐Full Calendar

  1. Add a controller to your ASP.Net Core project in the Controllers folder.将控制器添加到 Controllers 文件夹中的 ASP.Net Core 项目。
  2. Add Full Calendar to your page.将完整日历添加到您的页面。 ( Read this. ) 读这个。
  3. Full Calendar will call your API for the event data.完整日历将调用您的 API 以获取事件数据。 (reference the Full Calendar docs for the return JSON format) (有关返回 JSON 格式,请参阅完整日历文档)

Wishing you the best.祝你一切顺利。

I'd recommend going for a jQuery UI approach.我建议采用 jQuery UI 方法。 You can customise it freely (see their documentation)您可以自由自定义(请参阅他们的文档)

You can use AJAX/jQuery or something to get the dates from the database via a method in your controller.您可以使用 AJAX/jQuery 或其他东西通过控制器中的方法从数据库中获取日期。 Then display the calendar in a div.然后在 div 中显示日历。

Here's a jsfiddle.这是一个jsfiddle。

http://jsfiddle.net/Lhpc7zt2/1/ http://jsfiddle.net/Lhpc7zt2/1/

var events = [ 
{ Title: "Birthday", Date: new Date("12/12/2019") }, 
{ Title: "Christmas", Date: new Date("12/25/2019") }, 
{ Title: "Boxing Day", Date: new Date("12/26/2019") }
];

$("#calendar").datepicker({
beforeShowDay: function(date) {
    var result = [true, '', null];
    var tooltip = "";
    var matching = $.grep(events, function(event) {
        if (event.Date.valueOf() === date.valueOf()) {
        tooltip = event.Title;
        return true;
      }
    });

    if (matching.length > 0) {
        result = [true, 'event', tooltip];
    }
    return result;
}
});

To get the JSON from the controller:从控制器获取 JSON:

var events;    
$.getJSON('dateController/read', null, function(output) {
    events = output;
}

Then your controller action would be something like:那么您的控制器操作将类似于:

[HttpGet]
public IActionResult read()
{
    //Database call to read dates and convert them to JSON object...

    List<SelectedDates> highlightDates = new List<SelectedDates>();
        highlightDates.Add(new SelectedDates { Date = new DateTime(2019, 12, 
    1), Title = "Birthday" });

    return Json(highlightDates);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM