I have a scenario where the WCF returns the follwing data ( in the function given below) to a VIEW.
private List<KeyDatesCalendar> GetKeyDatesCalendarData()
{
//Dummy Data for BrandsCalendar CheckList
var keyDatesCalendar = new List<KeyDatesCalendar>()
{
new KeyDatesCalendar()
{
EventText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
EventDate = new DateTime(2011, 02, 09),
EventType = 3
},
new KeyDatesCalendar()
{
EventText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
EventDate = new DateTime(2011, 03, 05),
EventType = 3
},
new KeyDatesCalendar()
{
EventText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
EventDate = new DateTime(2011, 03, 06),
EventType = 4
},
};
The processing of the data in view is done by the following code:
initCalendars({
from : '02/01/2011',
to : '01/31/2013',
dates : [
@for(int i=0, l=@Model.KeyDatesCalendar.Count; i<l; i++)
{
@Html.Raw("['" + @Model.KeyDatesCalendar[i].EventDate.ToString("yyyy/MM/dd") + "'," + @Model.KeyDatesCalendar[i].EventType + ",'" + @Model.KeyDatesCalendar[i].EventText + "']" + (i < (l-1) ? "," : ""));
}
]
});
Instead of the hardcoded values in WCF method, how Do i recieve a JSON output and process the same in View.
I am a beginner here, appreciate your detail answers.
Thanks,
Adarsh
I would agree with many of the previous comments, if you’re using ASP.NET MVC you might as well do the JSON conversion from there (have a look at JsonResult class). However, if you really want the WCF service to return the result in JSON format, this blog post I wrote a while back might help.
Iain