{"id":639,"date":"2010-10-18T14:30:22","date_gmt":"2010-10-18T10:30:22","guid":{"rendered":"http:\/\/www.dhtmlx.com\/blog\/?p=639"},"modified":"2026-04-28T16:21:12","modified_gmt":"2026-04-28T13:21:12","slug":"dhtmlxscheduler-for-net-mvc","status":"publish","type":"post","link":"https:\/\/dhtmlx.com\/blog\/dhtmlxscheduler-for-net-mvc\/","title":{"rendered":"Event Calendar for ASP.NET MVC with dhtmlxScheduler"},"content":{"rendered":"\n        <div class=\"info-block\">\n            <div class=\"info-icon\">\n                <svg viewBox=\"0 0 14 16\">\n                    <path fill-rule=\"evenodd\" d=\"M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z\"><\/path>\n                <\/svg>\n\n                INFO\n            <\/div>\n\n            <div class=\"info-content\">\n                <p>\n                    For new clients, we recommend using <a href=\"https:\/\/dhtmlx.com\/docs\/products\/dhtmlxScheduler\/\" title=\"\">DHTMLX Scheduler<\/a> and \n                    integrating it with .NET by following our official <a href=\"https:\/\/docs.dhtmlx.com\/scheduler\/integrations\/dotnet\/howtostart-dotnet-core\/\" title=\"\" target=\"_blank\">guide<\/a>.                    \n                <\/p>\n            <\/div>\n        <\/div>\n    \n<p><strong>NOTE<\/strong>: We&#8217;re now offering DHTMLX Scheduler .NET, an optimized version for ASP.NET apps.<\/p>\n<p>This tutorial will lead you through the steps required to integrate dhtmlxScheduler into an <strong>ASP.NET MVC<\/strong> application. dhtmlxScheduler is a JavaScript scheduling calendar component, which can be used for a wide variety of use-cases connected to scheduling tasks. We will learn how to put this Ajax-based calendar on a web page, load events from .NET sever side and update them in the database when a user makes changes in the browser.<\/p>\n<p><a href=\"https:\/\/dhtmlx.com\/x\/download\/regular\/tutorials\/scheduler_aspnet_mvc.zip\">Download the final demo<\/a> to get a better understanding of the solution we&#8217;re about to build.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3792\" src=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/10\/img-scheduler-asp-net-flat.png\" alt=\"scheduler-asp-net-flat\" width=\"900\" height=\"518\" srcset=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/10\/img-scheduler-asp-net-flat.png 900w, https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/10\/img-scheduler-asp-net-flat-300x173.png 300w, https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/10\/img-scheduler-asp-net-flat-768x442.png 768w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/p>\n<p>Modern web apps impose ever higher demands on the user interface. In the case of standard controls, you can always use a built-in solution. However, with more complex controls \u2013 a calendar UI, for example \u2013 you are up against the problem. But here, third-party solutions can help. One of them is dhtmlxScheduler.<\/p>\n<p><!--more--><\/p>\n<h4>Preparation<\/h4>\n<p>First of all, you need to create a new project. Nothing specific, just an empty ASP.NET MVC project. Name it, for example, &#8220;My Calendar&#8221;. After that, create a database (or use any valid one) where you will save the calendar events. In the database, create the table &#8220;Events&#8221; with the following set of fields (all fields are mandatory):<\/p>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">\n<tbody>\n<tr>\n<td bgcolor=\"#d7dadd\"><strong>Field<\/strong><strong>Type<\/strong><strong>Description<\/strong><\/td>\n<\/tr>\n<tr>\n<td bgcolor=\"#f4f6fa\" width=\"25%\">id<\/td>\n<td bgcolor=\"#f4f6fa\" width=\"25%\">identity, primary key<\/td>\n<td bgcolor=\"#f4f6fa\" width=\"50%\">the ID of an event<\/td>\n<\/tr>\n<tr>\n<td bgcolor=\"#f4f6fa\" width=\"25%\">text<\/td>\n<td bgcolor=\"#f4f6fa\" width=\"25%\">text<\/td>\n<td bgcolor=\"#f4f6fa\" width=\"50%\">the description of an event<\/td>\n<\/tr>\n<tr>\n<td bgcolor=\"#f4f6fa\" width=\"25%\">start_date<\/td>\n<td bgcolor=\"#f4f6fa\" width=\"25%\">datetime<\/td>\n<td bgcolor=\"#f4f6fa\" width=\"50%\">the date and the time of an event start<\/td>\n<\/tr>\n<tr>\n<td bgcolor=\"#f4f6fa\" width=\"25%\">end_date<\/td>\n<td bgcolor=\"#f4f6fa\" width=\"25%\">datetime<\/td>\n<td bgcolor=\"#f4f6fa\" width=\"50%\">the date and the time of an event end<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>While the DB tool is open, you can add some test data to the &#8220;Events&#8221; table. If you downloaded the final demo package, you can find there MyCalendar.mdf file which already contains the necessary table and data.<\/p>\n<p>The next thing you need is the dhtmlxScheduler package, which can be downloaded from the <a href=\"https:\/\/dhtmlx.com\/docs\/products\/dhtmlxScheduler\/\">dhtmlxScheduler homepage<\/a>. Copy the content from the folder &#8216;codebase&#8217; to the folder &#8216;Scripts&#8217; of your project. The result of this step should look similar to the following:<\/p>\n<div id=\"attachment_643\" style=\"width: 527px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-643\" class=\"size-full wp-image-643\" title=\"dhtmlxScheduler Files\" src=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/10\/directory.gif\" alt=\"dhtmlxScheduler Files\" width=\"517\" height=\"467\" srcset=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/10\/directory.gif 517w, https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/10\/directory-300x270.gif 300w\" sizes=\"auto, (max-width: 517px) 100vw, 517px\" \/><p id=\"caption-attachment-643\" class=\"wp-caption-text\">dhtmlxScheduler Files<\/p><\/div>\n<p>Now that everything is ready, and all the necessary files are in place, you can proceed to the first step.<\/p>\n<h4>Step 1 &#8211; Initialization<\/h4>\n<p>First of all, you need to create a default view. Add a new controller &#8211; &#8220;CalendarController&#8221; &#8211; and create the &#8220;Index&#8221; view for it. Here is the content of <strong>Index.aspx<\/strong> file:<\/p>\n<div class=\"codecolorer-container html4strict default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"html4strict codecolorer\"><span class=\"sc2\">&lt;%@ Page <span class=\"kw3\">Language<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;C#&quot;<\/span> Inherits<span class=\"sy0\">=<\/span><span class=\"st0\">&quot;System.Web.Mvc.ViewPage&quot;<\/span> %&gt;<\/span><\/div><\/div>\n<p>The default view loads .js and .css files of the dhtmlxScheduler and initializes a full-screen scheduler. The second and third parameters in the \u2018scheduler.init&#8217; command define default date and mode, which will be in the calendar just after initialization. Except for the first line, the code doesn&#8217;t have anything .NET MVC-specific. Actually, it&#8217;s fully taken from a standard scheduler example.<\/p>\n<p>Now one more thing needs to be done \u2013 the updating of a default route. Switch the default route of the app to the newly-created controller in <strong>Global.asax.cs<\/strong>:<\/p>\n<div class=\"codecolorer-container c default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"c codecolorer\">public <span class=\"kw4\">static<\/span> <span class=\"kw4\">void<\/span> RegisterRoutes<span class=\"br0\">&#40;<\/span>RouteCollection routes<span class=\"br0\">&#41;<\/span><br \/>\n<span class=\"br0\">&#123;<\/span><br \/>\nroutes.<span class=\"me1\">IgnoreRoute<\/span><span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;{resource}.axd\/{*pathInfo}&quot;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n<br \/>\nroutes.<span class=\"me1\">MapRoute<\/span><span class=\"br0\">&#40;<\/span><br \/>\n<span class=\"st0\">&quot;Default&quot;<\/span><span class=\"sy0\">,<\/span> <span class=\"co1\">\/\/ Route name<\/span><br \/>\n<span class=\"st0\">&quot;{controller}\/{action}\/{id}&quot;<\/span><span class=\"sy0\">,<\/span> <span class=\"co1\">\/\/ URL with parameters<\/span><br \/>\nnew <span class=\"br0\">&#123;<\/span> controller <span class=\"sy0\">=<\/span> <span class=\"st0\">&quot;Calendar&quot;<\/span><span class=\"sy0\">,<\/span> action <span class=\"sy0\">=<\/span> <span class=\"st0\">&quot;Index&quot;<\/span><span class=\"sy0\">,<\/span> id <span class=\"sy0\">=<\/span> UrlParameter.<span class=\"me1\">Optional<\/span> <span class=\"br0\">&#125;<\/span> <span class=\"co1\">\/\/ Parameter defaults<\/span><br \/>\n<span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><\/div><\/div>\n<p>When all this is done and correct, you can run the app and see the next screen:<\/p>\n<div id=\"attachment_645\" style=\"width: 610px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-645\" class=\"size-full wp-image-645\" title=\"Scheduler on page\" src=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/10\/scheduler_preview.gif\" alt=\"Scheduler on page\" width=\"600\" height=\"449\" srcset=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/10\/scheduler_preview.gif 600w, https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/10\/scheduler_preview-300x224.gif 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><p id=\"caption-attachment-645\" class=\"wp-caption-text\">Scheduler on page<\/p><\/div>\n<p>If you don\u2019t see the screen above, most probably you didn\u2019t copy the scheduler\u2019s files to the folder &#8216;Scripts&#8217; correctly, so check it again.<\/p>\n<p>The calendar created with the dhtmlxScheduler has a clean and intuitive interface, and managing events is quite easy. To create new events, use the double click or click-and-drag commands. By clicking on tabs in the upper right-hand corner you can switch views: Day, Week, or Month.<\/p>\n<h4>Step 2 &#8211; Loading Data<\/h4>\n<p>The view we constructed in the previous step looks fine, but it doesn\u2019t contain any data, so now let&#8217;s change this. First, add &#8216;Model&#8217; to your application (just use &#8220;Model &gt; Add &gt; Add new item&#8221; and select &#8220;Data&#8221;,&#8221;Linq to SQL Classes&#8221;). To complete the process, drag-and-drop the &#8220;Events&#8221; table to the Model Designer, and then add one more action to the <strong>CalendarController.cs<\/strong>:<\/p>\n<div class=\"codecolorer-container c default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"c codecolorer\">public ActionResult Data<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n<span class=\"br0\">&#123;<\/span><br \/>\nMyEventsDataContext data <span class=\"sy0\">=<\/span> new MyEventsDataContext<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"kw1\">return<\/span> View<span class=\"br0\">&#40;<\/span>data.<span class=\"me1\">Events<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><\/div><\/div>\n<p>Define view for that action &#8211; <strong>Data.aspx<\/strong>:<\/p>\n<div class=\"codecolorer-container html4strict default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"html4strict codecolorer\"><span class=\"sc2\">&lt;%@ Page <span class=\"kw3\">Language<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;C#&quot;<\/span> Inherits<span class=\"sy0\">=<\/span><span class=\"st0\">&quot;System.Web.Mvc.ViewPage&quot;<\/span> ContentType<span class=\"sy0\">=<\/span><span class=\"st0\">&quot;text\/xml&quot;<\/span> %&gt;<\/span><br \/>\n<br \/>\n<span class=\"sc2\">&lt;% foreach <span class=\"br0\">&#40;<\/span>var myevent in Model<span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span> %&gt;<\/span><br \/>\n<br \/>\n<span class=\"sc-2\">&lt;![CDATA[&lt;%= String.Format(&quot;{0:MM\/dd\/yyyy HH:mm}&quot;,myevent.start_date) %&gt;]]&gt;<\/span><br \/>\n<span class=\"sc-2\">&lt;![CDATA[&lt;%= String.Format(&quot;{0:MM\/dd\/yyyy HH:mm}&quot;,myevent.end_date) %&gt;]]&gt;<\/span><br \/>\n<span class=\"sc-2\">&lt;![CDATA[&lt;%= myevent.text%&gt;]]&gt;<\/span><br \/>\n<br \/>\n<span class=\"sc2\">&lt;% <span class=\"br0\">&#125;<\/span> %&gt;<\/span>;<\/div><\/div>\n<p>This template outputs not HTML, but XML data. For each event it will output a block of XML data. An extra bit of code is used to provide data in the necessary format. If you need to add extra fields to the model, just add extra tags to the view.<\/p>\n<p>Slightly adjust the initialization code of your scheduler in <strong>Index.aspx<\/strong>:<\/p>\n<div class=\"codecolorer-container html4strict default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"html4strict codecolorer\">&lt;<span class=\"kw2\">script<\/span> <span class=\"kw3\">type<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;text\/javascript&quot;<\/span>&gt;<span class=\"sy0\">\/\/<\/span> &lt;!<span class=\"br0\">&#91;<\/span>CDATA<span class=\"br0\">&#91;<\/span><br \/>\nfunction init<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span> scheduler.config.xml_date <span class=\"sy0\">=<\/span> <span class=\"st0\">&quot;%m\/%d\/%Y %H:%i&quot;<\/span>; <span class=\"sy0\">\/\/<\/span> format of dates in XML scheduler.init<span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;scheduler_here&quot;<\/span>, new Date<span class=\"br0\">&#40;<\/span><span class=\"nu0\">2010<\/span>, <span class=\"nu0\">6<\/span>, <span class=\"nu0\">1<\/span><span class=\"br0\">&#41;<\/span>, <span class=\"st0\">&quot;month&quot;<\/span><span class=\"br0\">&#41;<\/span>; scheduler.load<span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;\/Calendar\/Data&quot;<\/span><span class=\"br0\">&#41;<\/span>; <span class=\"sy0\">\/\/<\/span>path to the newly created <span class=\"kw3\">action<\/span> <span class=\"br0\">&#125;<\/span><br \/>\n<span class=\"sy0\">\/\/<\/span> <span class=\"br0\">&#93;<\/span><span class=\"br0\">&#93;<\/span>&gt;&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">script<\/span>&gt;<\/div><\/div>\n<p>Well, you&#8217;ve just configured the format of dates (it&#8217;s the same as in Data.aspx) and defined the path to action &#8216;Data&#8217;. At this point, the running application will look like this:<\/p>\n<div id=\"attachment_648\" style=\"width: 610px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-648\" class=\"size-full wp-image-648\" title=\"Scheduler - Loading the events\" src=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/10\/scheduler_events.gif\" alt=\"Scheduler - Loading the events\" width=\"600\" height=\"451\" srcset=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/10\/scheduler_events.gif 600w, https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/10\/scheduler_events-300x225.gif 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><p id=\"caption-attachment-648\" class=\"wp-caption-text\">Scheduler &#8211; Loading the events<\/p><\/div>\n<p>We\u2019re halfway there. Just one more step, and we\u2019re almost done.<\/p>\n<h4>Step 3 &#8211; Saving to the Database<\/h4>\n<p>After all the manipulations described above, we&#8217;ve built a scheduler which loads the events data from the database, but that&#8217;s not enough. Our next goal is to save changes made on the client side to the server. First of all, create one more action &#8211; <strong>CalendarController.cs<\/strong>:<\/p>\n<div class=\"codecolorer-container c default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"c codecolorer\">public ActionResult Save<span class=\"br0\">&#40;<\/span>FormCollection actionValues<span class=\"br0\">&#41;<\/span><br \/>\n<span class=\"br0\">&#123;<\/span><br \/>\nString action_type <span class=\"sy0\">=<\/span> actionValues<span class=\"br0\">&#91;<\/span><span class=\"st0\">&quot;!nativeeditor_status&quot;<\/span><span class=\"br0\">&#93;<\/span><span class=\"sy0\">;<\/span><br \/>\nInt64 source_id <span class=\"sy0\">=<\/span> Int64.<span class=\"me1\">Parse<\/span><span class=\"br0\">&#40;<\/span>actionValues<span class=\"br0\">&#91;<\/span><span class=\"st0\">&quot;id&quot;<\/span><span class=\"br0\">&#93;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\nInt64 target_id <span class=\"sy0\">=<\/span> source_id<span class=\"sy0\">;<\/span><br \/>\n<br \/>\nMyEventsDataContext data <span class=\"sy0\">=<\/span> new MyEventsDataContext<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\nEvent myevent<span class=\"sy0\">;<\/span><br \/>\ntry<span class=\"br0\">&#123;<\/span><br \/>\n<span class=\"kw1\">switch<\/span> <span class=\"br0\">&#40;<\/span>action_type<span class=\"br0\">&#41;<\/span><br \/>\n<span class=\"br0\">&#123;<\/span><br \/>\n<span class=\"kw1\">case<\/span> <span class=\"st0\">&quot;inserted&quot;<\/span><span class=\"sy0\">:<\/span><br \/>\nmyevent <span class=\"sy0\">=<\/span> new Event<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\nmyevent.<span class=\"me1\">start_date<\/span> <span class=\"sy0\">=<\/span> DateTime.<span class=\"me1\">Parse<\/span><span class=\"br0\">&#40;<\/span>actionValues<span class=\"br0\">&#91;<\/span><span class=\"st0\">&quot;start_date&quot;<\/span><span class=\"br0\">&#93;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\nmyevent.<span class=\"me1\">end_date<\/span> <span class=\"sy0\">=<\/span> DateTime.<span class=\"me1\">Parse<\/span><span class=\"br0\">&#40;<\/span>actionValues<span class=\"br0\">&#91;<\/span><span class=\"st0\">&quot;end_date&quot;<\/span><span class=\"br0\">&#93;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\nmyevent.<span class=\"me1\">text<\/span> <span class=\"sy0\">=<\/span> actionValues<span class=\"br0\">&#91;<\/span><span class=\"st0\">&quot;text&quot;<\/span><span class=\"br0\">&#93;<\/span><span class=\"sy0\">;<\/span><br \/>\ndata.<span class=\"me1\">Events<\/span>.<span class=\"me1\">InsertOnSubmit<\/span><span class=\"br0\">&#40;<\/span>myevent<span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"kw2\">break<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"kw1\">case<\/span> <span class=\"st0\">&quot;deleted&quot;<\/span><span class=\"sy0\">:<\/span><br \/>\nmyevent <span class=\"sy0\">=<\/span> data.<span class=\"me1\">Events<\/span>.<span class=\"me1\">SingleOrDefault<\/span><span class=\"br0\">&#40;<\/span>ev <span class=\"sy0\">=&amp;<\/span>gt<span class=\"sy0\">;<\/span> ev.<span class=\"me1\">id<\/span> <span class=\"sy0\">==<\/span> source_id<span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\ndata.<span class=\"me1\">Events<\/span>.<span class=\"me1\">DeleteOnSubmit<\/span><span class=\"br0\">&#40;<\/span>myevent<span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"kw2\">break<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"kw1\">default<\/span><span class=\"sy0\">:<\/span> <span class=\"co1\">\/\/ &quot;updated&quot;<\/span><br \/>\nmyevent <span class=\"sy0\">=<\/span> data.<span class=\"me1\">Events<\/span>.<span class=\"me1\">SingleOrDefault<\/span><span class=\"br0\">&#40;<\/span>ev <span class=\"sy0\">=&amp;<\/span>gt<span class=\"sy0\">;<\/span> ev.<span class=\"me1\">id<\/span> <span class=\"sy0\">==<\/span> source_id<span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\nmyevent.<span class=\"me1\">start_date<\/span> <span class=\"sy0\">=<\/span> DateTime.<span class=\"me1\">Parse<\/span><span class=\"br0\">&#40;<\/span>actionValues<span class=\"br0\">&#91;<\/span><span class=\"st0\">&quot;start_date&quot;<\/span><span class=\"br0\">&#93;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\nmyevent.<span class=\"me1\">end_date<\/span> <span class=\"sy0\">=<\/span> DateTime.<span class=\"me1\">Parse<\/span><span class=\"br0\">&#40;<\/span>actionValues<span class=\"br0\">&#91;<\/span><span class=\"st0\">&quot;end_date&quot;<\/span><span class=\"br0\">&#93;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\nmyevent.<span class=\"me1\">text<\/span> <span class=\"sy0\">=<\/span> actionValues<span class=\"br0\">&#91;<\/span><span class=\"st0\">&quot;text&quot;<\/span><span class=\"br0\">&#93;<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"kw2\">break<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><br \/>\ndata.<span class=\"me1\">SubmitChanges<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\ntarget_id <span class=\"sy0\">=<\/span> myevent.<span class=\"me1\">id<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><br \/>\ncatch<br \/>\n<span class=\"br0\">&#123;<\/span><br \/>\naction_type <span class=\"sy0\">=<\/span> <span class=\"st0\">&quot;error&quot;<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><br \/>\n<br \/>\n<span class=\"kw1\">return<\/span> View<span class=\"br0\">&#40;<\/span>new CalendarActionResponseModel<span class=\"br0\">&#40;<\/span>action_type<span class=\"sy0\">,<\/span> source_id<span class=\"sy0\">,<\/span> target_id<span class=\"br0\">&#41;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><\/div><\/div>\n<p>It seems that we have a lot of code, but it&#8217;s quite simple in its logic. In the first lines, we specify the type of action from the incoming request. Then, depending on the type, we inserted, deleted, or updated the data in the database. And after the DB operation was completed, we rendered a response to the client-side scheduler.<\/p>\n<p>The file <strong>Save.aspx<\/strong> will look like this:<\/p>\n<div class=\"codecolorer-container html4strict default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"html4strict codecolorer\"><span class=\"sc2\">&lt;%@ Page <span class=\"kw3\">Language<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;C#&quot;<\/span> Inherits<span class=\"sy0\">=<\/span><span class=\"st0\">&quot;System.Web.Mvc.ViewPage&quot;<\/span> ContentType<span class=\"sy0\">=<\/span><span class=\"st0\">&quot;text\/xml&quot;<\/span>%&gt;<\/span><\/div><\/div>\n<p>&nbsp;<\/p>\n<p>The view shown above uses class &#8216;CalendarActionResponseModel&#8217; to transfer the necessary information from the action to the view. In <strong>CalendarController.cs<\/strong> we add:<\/p>\n<div class=\"codecolorer-container c default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"c codecolorer\">public class CalendarActionResponseModel<br \/>\n<span class=\"br0\">&#123;<\/span><br \/>\npublic String Status<span class=\"sy0\">;<\/span><br \/>\npublic Int64 Source_id<span class=\"sy0\">;<\/span><br \/>\npublic Int64 Target_id<span class=\"sy0\">;<\/span><br \/>\npublic CalendarActionResponseModel<span class=\"br0\">&#40;<\/span>String status<span class=\"sy0\">,<\/span> Int64 source_id<span class=\"sy0\">,<\/span> Int64 target_id<span class=\"br0\">&#41;<\/span><br \/>\n<span class=\"br0\">&#123;<\/span><br \/>\nStatus <span class=\"sy0\">=<\/span> status<span class=\"sy0\">;<\/span><br \/>\nSource_id <span class=\"sy0\">=<\/span> source_id<span class=\"sy0\">;<\/span><br \/>\nTarget_id <span class=\"sy0\">=<\/span> target_id<span class=\"sy0\">;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><\/div><\/div>\n<p>Now update the <strong>Index.aspx<\/strong> one more time (add code that will link updates on the client-side scheduler with the action &#8216;Save&#8217;) :<\/p>\n<div class=\"codecolorer-container html4strict default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"html4strict codecolorer\"><span class=\"sc2\">&lt;<span class=\"kw2\">script<\/span> <span class=\"kw3\">type<\/span><span class=\"sy0\">=<\/span><span class=\"st0\">&quot;text\/javascript&quot;<\/span>&gt;<\/span>\/\/ <span class=\"sc-2\">&lt;![CDATA[<\/span><br \/>\n<span class=\"sc-2\">function init() { scheduler.config.xml_date = &quot;%m\/%d\/%Y %H:%i&quot;; scheduler.init(&quot;scheduler_here&quot;, new Date(2010, 6, 1), &quot;month&quot;); scheduler.load(&quot;\/Calendar\/Data&quot;); var dp = new dataProcessor(&quot;\/Calendar\/Save&quot;); dp.init(scheduler); dp.setTransactionMode(&quot;POST&quot;, false); }<\/span><br \/>\n<span class=\"sc-2\">\/\/ ]]&gt;<\/span><span class=\"sc2\">&lt;<span class=\"sy0\">\/<\/span><span class=\"kw2\">script<\/span>&gt;<\/span><\/div><\/div>\n<p>If you launch the app now, the screen will look similar to the one from Step 2, but any changes or new events will be saved to the DB. Also, it will correctly restore after page reloading. So now we can proceed to the last step.<\/p>\n<h4>Step 4 &#8211; Improvements<\/h4>\n<p>The code we are using in \u2018SaveController\u2019 can be improved by using automatic bindings. In <strong>CalendarController.cs<\/strong>:<\/p>\n<div class=\"codecolorer-container c default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"c codecolorer\">public ActionResult Save<span class=\"br0\">&#40;<\/span>Event changedEvent<span class=\"sy0\">,<\/span> FormCollection actionValues<span class=\"br0\">&#41;<\/span><br \/>\n<span class=\"br0\">&#123;<\/span><br \/>\nString action_type <span class=\"sy0\">=<\/span> actionValues<span class=\"br0\">&#91;<\/span><span class=\"st0\">&quot;!nativeeditor_status&quot;<\/span><span class=\"br0\">&#93;<\/span><span class=\"sy0\">;<\/span><br \/>\nInt64 source_id <span class=\"sy0\">=<\/span> Int64.<span class=\"me1\">Parse<\/span><span class=\"br0\">&#40;<\/span>actionValues<span class=\"br0\">&#91;<\/span><span class=\"st0\">&quot;id&quot;<\/span><span class=\"br0\">&#93;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\nInt64 target_id <span class=\"sy0\">=<\/span> source_id<span class=\"sy0\">;<\/span><br \/>\nMyEventsDataContext data <span class=\"sy0\">=<\/span> new MyEventsDataContext<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\ntry<span class=\"br0\">&#123;<\/span><br \/>\n<span class=\"kw1\">switch<\/span> <span class=\"br0\">&#40;<\/span>action_type<span class=\"br0\">&#41;<\/span><br \/>\n<span class=\"br0\">&#123;<\/span><br \/>\n<span class=\"kw1\">case<\/span> <span class=\"st0\">&quot;inserted&quot;<\/span><span class=\"sy0\">:<\/span><br \/>\ndata.<span class=\"me1\">Events<\/span>.<span class=\"me1\">InsertOnSubmit<\/span><span class=\"br0\">&#40;<\/span>changedEvent<span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"kw2\">break<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"kw1\">case<\/span> <span class=\"st0\">&quot;deleted&quot;<\/span><span class=\"sy0\">:<\/span><br \/>\nchangedEvent <span class=\"sy0\">=<\/span> data.<span class=\"me1\">Events<\/span>.<span class=\"me1\">SingleOrDefault<\/span><span class=\"br0\">&#40;<\/span>ev <span class=\"sy0\">=&amp;<\/span>gt<span class=\"sy0\">;<\/span> ev.<span class=\"me1\">id<\/span> <span class=\"sy0\">==<\/span> source_id<span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\ndata.<span class=\"me1\">Events<\/span>.<span class=\"me1\">DeleteOnSubmit<\/span><span class=\"br0\">&#40;<\/span>changedEvent<span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"kw2\">break<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"kw1\">default<\/span><span class=\"sy0\">:<\/span> <span class=\"co1\">\/\/ &quot;updated&quot;<\/span><br \/>\nchangedEvent <span class=\"sy0\">=<\/span> data.<span class=\"me1\">Events<\/span>.<span class=\"me1\">SingleOrDefault<\/span><span class=\"br0\">&#40;<\/span>ev <span class=\"sy0\">=&amp;<\/span>gt<span class=\"sy0\">;<\/span> ev.<span class=\"me1\">id<\/span> <span class=\"sy0\">==<\/span> source_id<span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\nUpdateModel<span class=\"br0\">&#40;<\/span>changedEvent<span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"kw2\">break<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><br \/>\ndata.<span class=\"me1\">SubmitChanges<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\ntarget_id <span class=\"sy0\">=<\/span> changedEvent.<span class=\"me1\">id<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><br \/>\ncatch<br \/>\n<span class=\"br0\">&#123;<\/span><br \/>\naction_type <span class=\"sy0\">=<\/span> <span class=\"st0\">&quot;error&quot;<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><br \/>\n<span class=\"kw1\">return<\/span> View<span class=\"br0\">&#40;<\/span>new CalendarActionResponseModel<span class=\"br0\">&#40;<\/span>action_type<span class=\"sy0\">,<\/span> source_id<span class=\"sy0\">,<\/span> target_id<span class=\"br0\">&#41;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><\/div><\/div>\n<p>To give your calendar a slicker and glossier look, or to customize the color scheme, use the online Skin Builder for dhtmlxScheduler <strong>[deprecated]<\/strong>. Select one of &#8220;Glossy&#8221; skins to get a more modern look for the calendar. When you&#8217;re done with the customization, download the skin package (.css files and images), and unpack it in the folder &#8216;\u2018Scripts&#8217; (it will overwrite some old scheduler files).<\/p>\n<p>The running app after those updates will produce the final look:<\/p>\n<div id=\"attachment_649\" style=\"width: 610px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-649\" class=\"size-full wp-image-649\" title=\"Scheduler - Glossy skin\" src=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/10\/scheduler_final.png\" alt=\"Scheduler - Glossy skin\" width=\"600\" height=\"450\" srcset=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/10\/scheduler_final.png 600w, https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2010\/10\/scheduler_final-300x225.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><p id=\"caption-attachment-649\" class=\"wp-caption-text\">Scheduler &#8211; Glossy skin<\/p><\/div>\n<p>So let&#8217;s see what we&#8217;ve got: in just a few steps, we have implemented a web-based calendar that can be used in ASP.NET MVC and provide all the necessary functions: loading, saving, deleting, and updating events.<\/p>\n<p>Of course, perfection knows no bounds. You can define extra fields, add\/move calendar views, or redefine the scale and templates configuration (please refer to <a href=\"https:\/\/docs.dhtmlx.com\/scheduler\/\">dhtmlxScheduler documentation<\/a>). All these changes can be made simply by adding extra JavaScript commands in the &#8220;Index&#8221; view. There is no need for further updates in the &#8220;CalendarController.cs&#8221; code. So turn on your imagination and get going!<\/p>\n<p><strong>NOTE: If you&#8217;re using VB, please read this <a href=\"#comment-5061\">comment<\/a> (many thanks to Brian).<\/strong><\/p>\n<p><small>Posted by Ivan Petrenko<\/small><\/p>\n","protected":false},"excerpt":{"rendered":"<p>NOTE: We&#8217;re now offering DHTMLX Scheduler .NET, an optimized version for ASP.NET apps. This tutorial will lead you through the steps required to integrate dhtmlxScheduler into an ASP.NET MVC &#8230;<\/p>\n","protected":false},"author":2,"featured_media":3473,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[71,1],"tags":[33,37,14,15],"class_list":["post-639","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","category-uncategorized","tag-all-posts","tag-asp-net","tag-tips","tag-dhtmlxscheduler"],"_links":{"self":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts\/639","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/comments?post=639"}],"version-history":[{"count":10,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts\/639\/revisions"}],"predecessor-version":[{"id":15464,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts\/639\/revisions\/15464"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/media\/3473"}],"wp:attachment":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/media?parent=639"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/categories?post=639"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/tags?post=639"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}