Saving multiple events

When I’m trying to save an event AFTER I already had created an event or made changes to one, it doesn’t save. If I keep making changes, nothing is getting posted to the server. Part of my code in my init() function is:

scheduler.init(“scheduler”, new Date(y, m, day), “week”);
scheduler.load("/Calendar/Data");
var dp = new dataProcessor("/Calendar/Save");
dp.init(scheduler);
dp.setTransactionMode(“POST”, false);

After doing some debugging, I’ve found that when I’m making changes to an event the Save function in my calendar Controller isn’t getting posted; however it does happen SOMETIMES. It’s not consistent.

Which code you are using on server side, custom or based on connector ?
dp.setTransactionMode(“POST”, false); - this line switches data sending to mode, which is not compatible with connectors. So it will work only with custom backend.

It’s custom, here’s the code:

public ActionResult Save(Events changedEvent, FormCollection actionValues)
{
String action_type = actionValues["!nativeeditor_status"];
Int64 source_id = Int64.Parse(actionValues[“id”]);
Int64 target_id = source_id;

            try
            {
                switch (action_type)
                {
                    case "inserted":
                        var companyID = Convert.ToInt16(Session["companyID"].ToString());
                        changedEvent.companyID = companyID;
                        context.Events.Add(changedEvent);
                        break;
                    case "deleted":
                        changedEvent = context.Events.SingleOrDefault(ev => ev.eventsID == source_id);
                        context.Events.Remove(changedEvent);
                        break;
                    default: // "updated"
                        changedEvent = context.Events.SingleOrDefault(ev => ev.eventsID == source_id);
                        UpdateModel(changedEvent);
                        break;
                }
                context.SaveChanges();
                target_id = changedEvent.eventsID;
            }
            catch
            {
                action_type = "error";
            }
            return View(new CalendarActionResponseModel(action_type, source_id, target_id));
        }

Hi,
please check browser console, are there any error messages?

There are no error messages in the browser console.

I’ve done some additional debugging. It seems as if it’s only happening when it’s a new event and I want to go back into the event to change it for some reason. I’d have to reload the page and then make the change.

Check the action response after inserting new event. Most likely it contains invalid ‘target_id’ and event is unavailable until it’s reloaded with the correct id

in the last line of code:
return View(new CalendarActionResponseModel(action_type, source_id, target_id));

the variables’ values when i add a new event are:
action_type: inserted
source_id: 1364904460653
target_id: 70

this makes sense (for target_id) because I do have it getting set in the switch statement after I save the db context

Hi,
yes that seems correct.
Does action response have correct Content-Type(text/xml or application/xml), is response xml valid?

If response is rendered from aspx view, content type may be specified in attributes of Page directive:
<%@ Page Language=“C#” Inherits=“System.Web.Mvc.ViewPage” ContentType=“text/xml” %>
Is it there?

Yes. I’m using Razor Views and Data.cshtml file reads:
@{
Layout = null;
Response.ContentType = “application/xml”;
}

@foreach (var myevent in Model) { }

Hi,
this is Data action view, I meant Save action(the one that is triggered to render create/update/delete response).
cshtml might look like following:
@{
Layout = null;
Response.ContentType = “text/xml”;
}


I didn’t have the Reponse.ContentType in my Save action. So I changed it to:
@{
Layout = null;
Response.ContentType = “text/xml”;
}


and it didn’t work, but I just changed it to:

@{
Layout = null;
Response.ContentType = “application/xml”;
}


Right now that seemed to have fixed it. I will do some more thorough testing and respond back to this thread.

This is still not working if I try to make a change to the calendar event right after I add it.

Please attach the demo, so I could test it

I sent you a PM with the url and login information.

I am having this exact same error, I insert an even successfully and then when i try to update this event it does not update, no call is made to the controller. If i insert then refresh the page and then update the update is done successfully.

Was this solution solved. My code is exactly the same as the posted code in this thread.

Urgent response needed.

Thank you

Please inspect the the response of the first update request. In the Chrome Dev Tools you can find the ‘Network’ tab and find a request which ends with ‘Save/…editing=true’

The one usual reason of such issue is incorrect response from the first update request. It is in XML and client-side component relies on browser’s XML API to process it.
When the response is not recognized as XML (whether it’s due incorrect content type, or the invalid document), an error happens which breaks further processing.

So check the response and make sure it’s a valid XML

Thank you, i found if i changed the first line on Save.aspx to
<%@ Page Language=“C#” Inherits=“System.Web.Mvc.ViewPage” ContentType=“text/xml” %>
Then the save works perfectly. If I have System.Web.Mvc.ViewPage then it breaks and comes through as text/html

My issue now is parameters I added to the actionvalues, they came through fine before but now after saving, when I update, this custom parameter could not be found (in controller). I tried adding this to the save but was unsuccessful:


What am I missing?

Urgent response please
Thanks