Chaitanya Moganti
Chaitanya Moganti

Reputation: 11

Why it was not rendering events in full-calendar from WEB SERVICE?

//My web-service method WebService1.asmx

[WebMethod]    
[ScriptMethod]    
public string GetAllEvents()    
{    
    var list = new List<string>();
    list.Add("[{\"id\":\"36\"title\":\"Birthday party\",\"start\":\"2013-09-18\",\"end\":\"2013-09-18\",\"allDay\":false}]");
    JavaScriptSerializer jss = new JavaScriptSerializer();
    string strJSON = jss.Serialize(list.ToArray());
     return strJSON;
}

//My jQuery snippet

$("#fullcalendar").fullCalendar({

eventSources: 

[    
  {         
     url: "http://localhost:49322/WebService1.asmx/GetAllEvents",         
     type: 'POST',         
     dataType: "json",         
     contentType: "application/json; charset=utf-8",         
 }    
]    
});

Upvotes: 0

Views: 357

Answers (1)

I4V
I4V

Reputation: 35353

You are on the wrong track.

  • Don't form your json strings manually using string operations (As in your case, it is an invalid json).
  • Don't return string from your web method, return the real object

It should be something like this:

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public List<Event> GetAllEvents()
{
    List<Event> events = .......
    ..fill the list....
    return evetns;
}



public class Event
{
    public int id { get; set; }
    public string title { get; set; }
    public string start { get; set; }
    public string end { get; set; }
    public bool allDay { get; set; }
}

Upvotes: 2

Related Questions