views:

58

answers:

2

Hello! So i've recently got into Silverlight development. So far i've managed to create a single Siverlight XAML view which pulls in data from an SQL Server Database using the ADO.Net Entity Framework and displays the data in a Silverlight DataGrid. I can also perform simple editing and update functionality on the data and persist it back to the database. At this point my understanding falls down. From what I gather, the Silverlight Client Application is hosted inside an ASP.NET or ASP.Net MVC web application. Normally I would just build a website using ASP.Net MVC and use a few jquery controls etc. to spice up the interface on each view. How do i go about using these different Silverlight XAML views that I create in my ASP.Net MVC application like they were MVC Views? Have I totally missed something here?

Help greatly appreciated.

A: 

In order to update your data model from your Silverlight application (which is running on your client's machine) is to utilize WCF (Windows Communication Foundation). Your Silverlight application will communicate to your server using WCF, and none of that has really anything to do with how you're serving up your Silverlight app (whether you're using Webforms or MVC).

Joseph
So does it become irrelevant that your hosting the application in ASP.Net or MVC? - And essentially it just becomes a purely Silverlight based website!?
Goober
This is basically correct. You can think of Silverlight just like Flash. Flash is pretty much just loaded into a webpage, but it's not really connected to the webpage in any manner (in most cases anyways). The Silverlight app is basically self contained.
TehOne
I disagree - you can use MVC views to provide REST based information to a Silverlight control, just as you would to Javascript / jQuery client-side components. Silverlight is self-contained, but since it can communicate both with your server and with the other HTML on the page (via DOM bridge), it can be as closely integrated with your site as you'd like.
Jon Galloway
Yes, you can certainly use MVC views to profide REST based information, but that still doesn't have much to do with the Silverlight application itself. It's just something for the Silverlight application to consume, and in this respect it's not much different then a web service or WCF. And as I stated, in most cases the Flash or Silverlight application will not directly communicate with the page that's hosting it. It is possible of course, but in most cases it doesn't happen.
TehOne
@tehone, I also disagree. In almost every Silverlight app I've made, the app interacts with the page. Often times, Silverlight is used to supplement the functionality of a page, not be the entire page. Silverlight can also be used in place of javascript to be the a way of manipulating the DOM. The different MVC views can provide different init params to load up the Silverlight app
Jacob Adams
+2  A: 

RIA Models

There are two different models for integrating Silverlight (or any RIA technology) into your website:

  • Entire Silverlight application hosted in simple website
  • Silverlight controls integrated into a website with other interaction (forms, jQuery, etc.)

Either model works well, it's up to you to decide which works better in your scenario.

Silverlight communication with the server

Your Silverlight application is a plugin hosted in a browser, so it's best to think of it like jQuery or other client-side code. There are several ways to communicate back to the server:

Silverlight supports WebClient and HttpWebRequest, so you can get as low-level as you'd like in your client-server communication. I really recommend looking at RIA Services since it handles not only the communications, but also the validation rules.

Silverlight integration with HTML / Javascript

Silverlight can both call and be called from Javascript via the HTML bridge. This means that your Silverlight components can be as closely integrated with your web-page as you'd like. Silverlight can also directly interact with the DOM - setting and reading form values, changing CSS properties, etc. You can do just about anything you'd do in Javascript via the HTML bridge if you'd like.

Jon Galloway