Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I try to retrieve datas from cloud, for example Windows Azure Mobile Service and push to the View() to display them, but unfortunately I got the error "**An exception of type 'System.InvalidOperationException' occurred in System.Web.dll but was not handled in user code**". Can anyone please help me ?
Thank you in advanced !

Here is my Controller:
C#
using Microsoft.WindowsAzure.MobileServices;
using MyMVC.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MyMVC.Controllers
{
    public class HomeController : Controller
    {

        List<TJamData> items = null;


        public ActionResult Jam()
        {

            takedata();
            return View(items);



        }

        private async void takedata()
        {


            MobileServiceClient m_MobileService = new                    MobileServiceClient("https://staupilot.azure-mobile.net/", "yLitRKWFZcWLEErPeuThcoZhjXCyiV69");
            IMobileServiceTable<TJamData> tJamTbl = m_MobileService.GetTable<TJamData>();
            items = await tJamTbl.Take(500)
                 .Where(todoItem => todoItem.IsActive == true)
                .ToListAsync();


        }
    }
}



And here is the Model:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MyMVC.Models
{
    public class TJamData
    {

        public int Id { get; set; }

        public string HighwayName { get; set; }

        public string HighwayFrom { get; set; }

        public bool IsActive { get; set; }

        public string HighwayTo { get; set; }

        public string HighwayDirection { get; set; }

        public DateTime DateTime { get; set; }

        public DateTime StartDate { get; set; }

        public DateTime EndDate { get; set; }

        public string OriginalMessage { get; set; }

        public string StartLocation { get; set; }

        public string EndLocation { get; set; }

        public float TrafficJamLength { get; set; }

        public string Provider { get; set; }

        public int JamMessageType { get; set; }
    }
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900