ASP.NET中MVC从后台控制器传递数据到前台视图的方
编程学习 2021-07-04 22:41www.dzhlxh.cn编程入门
这篇文章主要介绍了ASP.NET中MVC从后台控制器传递数据到前台视图的方式,以实例形式较为详细的分析了asp.net中MVC数据传递的具体实现方法,需要的朋友可以参考下
本文实例讲述了ASP.NET中MVC从后台控制器传递数据到前台视图的方式。分享给大家供大家参考。具体分析如下:
数据存储模型Model:
代码如下:
public class CalendarEvent
{
public string id { get; set; }
public DateTime start { get; set; }
public DateTime end { get; set; }
public string backgroundColor { get; set; }
public string title { get; set; }
public string allDay { get; set; }
}
{
public string id { get; set; }
public DateTime start { get; set; }
public DateTime end { get; set; }
public string backgroundColor { get; set; }
public string title { get; set; }
public string allDay { get; set; }
}
前台接收显示数据视图View:
代码如下:
<script type="text/javascript">
$(function () {
//calendar handle data as follows:
$(function () {
//calendar handle data as follows:
var events = [];
$.ajax({
url: "/DeploymentTask/CalendarData",
success: function (data) {
events = data;
},
async: false
});
$("#calendar").fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
//right: 'month,agendaWeek,agendaDay'
right: 'month'
},
selectable: true,
weekMode: 'variable',//fixed,variable,liquid
events: events,
defaultEventMinutes: 1440 //默认事件长度为一天
});
});
</script>
后台处理数据控制器Controller:
代码如下:
public JsonResult CalendarData()
{
Operation op = new Operation();
List<CalendarEvent> calendarData = op.GetData();
return Json(calendarData, JsonRequestBehavior.AllowGet);
}
{
Operation op = new Operation();
List<CalendarEvent> calendarData = op.GetData();
return Json(calendarData, JsonRequestBehavior.AllowGet);
}
希望本文所述对大家的asp.net程序设计有所帮助。