本文實例講述了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; } }
前台接收顯示資料視圖View:
<script type="text/javascript"> $(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); }
希望本文所述對大家的asp.net程式設計有所幫助。
更多ASP.NET中MVC從後台控制器傳遞資料到前台視圖的方式相關文章請關注PHP中文網!