views:

948

answers:

1

Previously, I was passing information to a Silverlight control inside of the Page_Load method. i.e.

protected void Page_Load(object sender, EventArgs e)
{
   MainContainer.InitParameters = "info=" + CurrentUserID.ToString();
}

In MVC, without the concept of a code-behind, I've passed the user ID as part of the model, but the following code doesn't seem to be working:

<asp:Silverlight id="MainContainer"
   InitParameters="info=<%= Model.CurrentUserID %>" runat="server"
   Source="~/ClientBin/SilverlightControls.xap" ... />

If you look at the code that gets rendered to the browser, it is escaping the MVC tags, so it gets sent like this:

value="info=&lt;%= Model.CurrentUserID %>"

If I try hardcoding InitParameters="info=1", it works.

+2  A: 

Don't use the <asp:Silverlight runat="server" /> control, it's a webforms control and doesn't really belong in the MVC world. You need to create the <object> tag yourself - maybe create your own Html helper extension method to create it.

Have a look at this blog post: Integrating Silverlight and ASP.NET MVC

HTH, Charles

Charlino