Tuesday, January 29, 2013

MVC 3 and Silverlight 4 db passing

private void UserControl_Loaded(object sender, RoutedEventArgs e)
    {
      WebClient wc = new WebClient();
      wc.OpenReadCompleted += 
        new OpenReadCompletedEventHandler(wc_OpenReadCompleted);
      wc.OpenReadAsync(new Uri("http://localhost:49520/Products/Index/"));
    }

    void wc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
    {
      DataContractJsonSerializer json = 
           new DataContractJsonSerializer(typeof(List<Product>));
      IList<Product> result = (List<Product>)(json.ReadObject(e.Result));
      MyGrid.ItemsSource = result;
    }
  }

No comments: