Asp.net core 我找不到在mssql上更新日历事件的方法。发布到我的razor页面不起作用(400错误)
使用日历中的自定义按钮更新的代码:Asp.net core 我找不到在mssql上更新日历事件的方法。发布到我的razor页面不起作用(400错误),asp.net-core,Asp.net Core,使用日历中的自定义按钮更新的代码: myCustomButton: { text: 'Save Events', click: () => { var allevents = calendar.getEvents(); $.ajax({
myCustomButton: {
text: 'Save Events',
click: () => {
var allevents = calendar.getEvents();
$.ajax({
type: 'POST',
contentType: 'application/json',
dataType: 'json',
data: allevents,
url: '/Wishes/Individual/Update',
headers: {
'RequestVerificationToken': '@antiforgery.GetAndStoreTokens(HttpContext).RequestToken'
},
success: function (response) {
alert: ('success');
},
failure: function (response) {
alert: ('failure');
}
});
}
},
根据您的描述和代码,您似乎希望通过发出AJAX post请求将FullCalendar中的所有事件发布到Razor页面处理程序,然后在数据库中保存/更新事件 要实现该需求,可以参考以下示例 在JavaScript客户端上 Razor页面处理程序方法 测试结果
您解决了这个问题吗?
customButtons: {
myCustomButton: {
text: 'Save Events',
click: function () {
var allevents = calendar.getEvents();
var events = [];
$.each(allevents, function (index, event) {
//console.log(event);
// include only expected data (such as title, start and end etc) in json object `newevent`
// instead of all information of calendar event
var newevent = { "title": event.title, "start": event.start, "end": event.end };
events.push(newevent);
});
$.ajax({
type: 'POST',
contentType: 'application/json',
dataType: 'json',
data: JSON.stringify(events),
url: '/Wishes/Individual/Update',
headers: {
'RequestVerificationToken': '@antiforgery.GetAndStoreTokens(HttpContext).RequestToken'
},
success: function (response) {
alert: ('success');
},
failure: function (response) {
alert: ('failure');
}
});
alert('clicked the custom button!');
}
}
},
public IActionResult OnPostUpdate([FromBody]List<Event> events)
{
//code logic here
return Content("ok");
}
public class Event
{
public string title { get; set; }
public string start { get; set; }
public string end { get; set; }
// defind other properties
// such as groupId, url etc based on your requirements
}