views:

53

answers:

2

I'm considering the scenario where an MVC view would pass the model to a Silverlight application (to display preferably as a modal form), which in turn would send back the updated model to the view before submitting. Is this at all possible?

+2  A: 

This is not a common supported scenario with ASP.NET MVC. Silverlight applications are not intended to be used as views. You could have normal views embedding a Silverlight application and setting properties based on the passed model, but posting values back to the controller wouldn't be easy. You will need to use a WebClient in the Silverlight application to talk to the server. Not as easy as a plain html form with input fields and a submit button.

Darin Dimitrov
Is there a mechanism for an ASP.NET page to retrieve data from an embedded Silverlight app?
ericdes
Yes, the Silverlight application need to use an http client like `WebClient` to send an HTTP request to the ASP.NET application.
Darin Dimitrov
+2  A: 

To talk from Asp.net to silverlight you can use params: See this or this

I don't think the Silverlight control/app should be posting the page (causing a refresh/reload) Silverlight is perfect for a nice async experience. But anyway, you could maybe invoke a Javascript function from silverlight and then in your JS do a postback. See this

I would recommend something like WCF Data Services, It allows you to expose any IQueryable objects through a service, then you can use Linq to consume it and entity objects are automatically created in visual studio so that you can update or delete objects if you're exposing a database.

You could maybe send something like user ID (model Id) from asp.net to silverlight with a param, then silverlight can call a wcf data service to pull the actual user. After processing it can then push/edit/delete that object again through the WCF data service. You can get up to speed with WCF quickly.

Hope that was helpful!?

giddy
Yes, I would send the model ID so Silverlight could retrieve the data from the database, an asynchronous update would be made, which in turn would invoke a Javascript function on the web page which would update the modified data without reloading the page. It sounds good, I just hope there won't be too much plumbing code!
ericdes
@ericdes " _invoke a Javascript function on the web page which would update the modified data without reloading the page_ " WCF Services would help you here by allowing you do perform CRUD operations without much plumbing. *straight from silverlight*, plus you get linq. If you don't want to go that way, the other option I see is using a webservice and invoking that service from javascript.(I think MVC has some Ajax helpers right?)
giddy