Scheduler in MVC

I am creating the equivalent of the custom lightbox control in MVC3.

I have followed the code at scheduler-net.com/docs/lightbox. … definition , but when i select an empty sliot on the scheduler(where no id is defined) the code falls over (as there is no id to assign to the hidden buttons in the view).

What was done in the code to prevent this?

The view code is

@model ViewModel.ScheduledActivityViewModel
@using (Html.BeginForm("Save", "PartialView"))
{

@Html.Hidden("id", Model.scheduledEvent.id)
<p>
<input type="submit" name="actionButton" value="Save" />
<input type="submit" value="Close" />
<input type="submit" name="actionButton" value="Delete" />
</p>

}

The code in the controller is

public ActionResult PartView(int id)
        {
            ScheduledActivityViewModel vm = new ScheduledActivityViewModel();
            var context = new ScheduledActivitiesDataContext();
            vm.scheduledEvent = context.Events.SingleOrDefault(e => e.id == id);
            
            return View(vm);
        }

Note that other than the view model the code is the same as that used in the example.

Any help would be greatly appreciated.

Hello,
check code from the sample

        public ActionResult LightboxControl(Event ev)
        {
            var context = new DHXSchedulerDataContext();
            var current = context.Events.SingleOrDefault(e => e.id == ev.id);
            if (current == null)
                current = ev;
            return View(current);
        }

you should handle case when new entry is added( which means data context doesn’t contains it). you may use mvc model binder(as in sample) or create Event manually, Request.Form contains all needed values - start_date, end_date, temporary id, etc

Thanks that has helped a lot,

When i save or cancel i get an action error after DataAction(actionValues) is called (an error is returned). Is there something specific that i need to do?

I can’t see what the error is, as it appears within the dhtmlx DataAction method.

Hello,

Please note that we have separate forum - “Scheduler for ASP.NET MVC” under dhtmlxScheduler section, please post your questions there.

Kind regards,
Ilya

Thank you… any idea what is likely to cause the DataAction issue?

How exactly do you process this action?
please post some code, or attach file with controller

The code on the save event in the controller is …

public ActionResult Save(Event changedEvent, FormCollection actionValues)
        {
            ScheduledActivitiesDataContext data = new ScheduledActivitiesDataContext();
            var action = new DataAction(actionValues);

The error occurs when it gets passed to the dhtmlx.DataAction() method.

The controller for the view is

public ActionResult LB(Event ev)
        {
            
            ScheduledActivityViewModel vm = new ScheduledActivityViewModel();

          
            vm.scheduledEvent = context.Events.SingleOrDefault(e => e.id == ev.id);
            if (vm.scheduledEvent == null)
                vm.scheduledEvent = ev;
            return View(vm);
        }

And the view is coded as

@model ViewModel.ScheduledActivityViewModel
@using (Html.BeginForm("Save","PartialViewInLightbox"))
{


@Html.Hidden("id", Model.scheduledEvent.id)

<input type="text" name="text" value="@Model.scheduledEvent.text"/>



<span class="label">From</span><input id="2" name="start_date"  type="text" value="@Model.scheduledEvent.start_date"/><span class="label">to</span>
<input id="3" name="end_date" type="text" value="@Model.scheduledEvent.end_date"/>


<p>
<input type="submit" name="actionButton" value="Save"  />
<input type="submit" value="Cancel" />
<input type="submit" name="actionButton" value="Delete" />
</p>


}

Hi,
looks like i don’t quite understand what exactly goes wrong

do you get a runtime error? if so what exception message is?

or DataAction’s type is ‘Error’ ?

var action = new DataAction(actionValues);

if yes, it is supposed to be so. This is needed to define if action is called by native scheduler’s controls(such as default lightbox, or drag’n’drop) or by custom lightbox.
If action type is recognized(it’s insert, update or delete) we can process it common way
scheduler-net.com/docs/managing_ … ode_sample
Otherwise you may need process form data in some other way, like it shown in this sample
scheduler-net.com/docs/lightbox.html#crud_logic

to use the same logic for both types of operations(custom lighbox’s and native scheduler’s) your form must send one extra field “!nativeeditor_status” with operation type - “inserted”, “updated” “deleted”, “error”

Hi,

Thanks that helps a lot.

What i am noticing when implementing the code from the secnd page that you have linked to is that the AjaxSaveResponse does not have two overloads? Am i therefore using an out of daye version of the dhtmlx code?

Also, when i select the buttons the partial view submits and then becomes a blank form.

Is there some code that i am missing?

Hello,

must be a mistake in that article.
In case of custom lightbox, response should be rendered by other class

return (new SchedulerFormResponseScript(action, changedEvent));

sorry for the inconvenience

Hello,
I also have the same problem, when i select the buttons the partial view submits and then becomes a blank form and i use return (new SchedulerFormResponseScript(action, changedEvent));

Thank you,
Flavia

Hello,

I also have the same problem, when i select the buttons the partial view submits and then becomes a blank form and I use: return (new SchedulerFormResponseScript(action, changedEvent));

Thank you,
Flavia

Hello,
can you attach some demo where the issue can be reproduced?