Quantcast
Channel: CodeProject Latest postings for ASP.NET
Viewing all articles
Browse latest Browse all 3938

Show DataTable in Json

$
0
0
Hi,
I need help for show datatable in Json

My project is MVC:

My AgendaModel

<pre>        public List<AgendaModel> MostrarTodosCalendar()
        {
            List<AgendaModel> lista = new List<AgendaModel>();
            AgendaModel item;
            DAL objDAL = new DAL();string sql = "SELECT id, title, start, end, AllDay, Color, TextColor FROM agenda";
            DataTable dt = objDAL.RetDataTable(sql);for (int i = 0; i < dt.Rows.Count; i++)
            {
                item = new AgendaModel
                {

                    Id = dt.Rows[i]["Id"].ToString(),
                    Title = dt.Rows[i]["Title"].ToString(),
                    Start = dt.Rows[i]["Start"].ToString(),
                    End = dt.Rows[i]["End"].ToString(),//AllDay = dt.Rows[i]["Allday"].ToString(),
                    Color = dt.Rows[i]["Color"].ToString(),
                    TextColor = dt.Rows[i]["TextColor"].ToString()

                };

                lista.Add(item);
            }

            return lista;
        }



My View: Index:

function CriarEventosCalendario() {

       var events = [];


       @{
           foreach(var item in (List<AgendaModel>)ViewBag.ListaEventos)
                  {<text>events.push({
                    'id': @item.Id,
                    'title': '@item.Title',
                    'start': '@item.Start',
                    'end': '@item.End',
                    'allDay': false,
                    'color': '@item.Color',
                    'textColor': '@item.TextColor'
                  });</text>

           }

       }


I want to convert to JSON because fullcalendar is not showing the data as it currently is.

Viewing all articles
Browse latest Browse all 3938


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>