|
|
|
Fullcalendar ครับ สอบถามเกี่ยวกับการแสดง Event (MVC C#.net) |
|
|
|
|
|
|
|
มันเป็น HTML นะครับ คุณน่าจะต้องใช้พวก Client Script ในการดักจับ Event แล้วให้มัน PostBack ไปที่ C# ครับ
|
|
|
|
|
Date :
2017-09-05 10:24:09 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ดูตรง events: ของ javascript ดีๆ มันไปโหลด ajax มา
Code (JavaScript)
$('#calendar').fullCalendar({
customButtons: {
activity: {
text: 'เพิ่มกิจกรรม',
click: function () {
window.location = '/Activity/Create';
}
}
},
header: {
left: 'activity',
center: 'title',
right: 'today prev,next',
},
buttonText: {
today: 'วันนี้',
month: 'เดือน',
},
//dayClick: function (date, jsEvent, view) {
// window.location = '/Activity/Detail/' + date.format();
//},
defaultView: 'month',
eventLimit: true, // allow "more" link when too many events
navLinks: false, // can click day/week names to navigate views
locale: moment().locale('th'),
viewRender: function (view, element) {
setTimeout(function () {
var strDate = $.trim($(".fc-center").find("h2").text());
var arrDate = strDate.split(" ");
var lengthArr = arrDate.length;
var newstrDate = "";
for (var i = 0; i < lengthArr; i++) {
if (lengthArr - 1 == i) {
var yearBuddha = parseInt(arrDate[i]) + 543;
newstrDate += yearBuddha;
} else {
newstrDate += arrDate[i] + " ";
}
}
$(".fc-center").find("h2").text(newstrDate);
$('.fc-toolbar').find('.fc-button-group').addClass('btn-group');
$('.fc-toolbar').find('.fc-button').removeClass('fc-state-default fc-corner-left fc-corner-right').addClass('btn btn-default btn-flat');
$('.fc-toolbar').find('.fc-prev-button').html($('<span />').attr('class', 'glyphicon glyphicon-chevron-left'));
$('.fc-toolbar').find('.fc-next-button').html($('<span />').attr('class', 'glyphicon glyphicon-chevron-right'))
$(".fc-left").find(".fc-activity-button").removeClass('fc-button btn-default').addClass('btn-primary').html('<i class="fa fa-plus-circle"></i> เพิ่มกิจกรรม');
}, 5);
},
events: {
url: '/Activity/Feed',
type: 'post',
data: {
'__RequestVerificationToken': $('input[name="__RequestVerificationToken"]', $('#__AjaxAntiForgeryForm')).val()
},
error: function () {
alert('there was an error while fetching events!');
},
//success: function (events) {
// $('#calendar').fullCalendar('removeEvents');
// $('#calendar').fullCalendar('addEventSource', events);
// $('#calendar').fullCalendar('rerenderEvents');
//}
//color: 'yellow', // a non-ajax option
//textColor: 'black' // a non-ajax option
}
});
Code (C#)
//
// POST: Activity/Feed
[Authorize]
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Feed(string start, string end)
{
var currentUser = System.Web.HttpContext.Current.User;
var startDate = DateTime.ParseExact(start, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
var endDate = DateTime.ParseExact(end, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
var output = new List<dynamic>();
context.Activities
.Where(m => m.StartAt >= startDate && m.StartAt <= endDate)
.ToList().ForEach(m =>
{
output.Add(new
{
title = m.Name,
start = m.StartAt.AddDays(1).Date,
end = m.EndAt.AddDays(1).Date,
url = Url.Action("Detail", "Activity", new { id = m.Id }),
backgroundColor = m.StartAt.CompareTo(DateTime.Today) >= 0 ? "#3c8dbc" : "#f39c12", //Primary (light-blue), yellow
borderColor = m.StartAt.CompareTo(DateTime.Today) >= 0 ? "#3c8dbc" : "#f39c12", //Primary (light-blue), yellow
});
});
return Json(output, JsonRequestBehavior.AllowGet);
}
|
|
|
|
|
Date :
2017-09-06 11:34:42 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@admin
mvc ไม่มี postback แล้ว
อธิบายแบบนั้นเดี๋ยวลูกค้าสับสนนะ
|
|
|
|
|
Date :
2017-09-06 11:38:30 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|