views:

217

answers:

3

I'd like to see if anyone out there can steer me in the right direction for linking up a Silverlight project with an MVC2 one. I know how to get it started but how do I get the .xap to show in the View? Looking for a good tutorial or blog?

+1  A: 

I didn't find a nice blog or tutorial about doing specifically what you're asking, but I did try it out myself.

In VS2010, I created a new project of type Silverlight application. During the process, it asked what type of web project I would like to associate and I selected MVC. This automatically created an MVC2 web application with a ClientBin directory. After building the solution, my ClientBin was populated with the *.xap file. If you need to manually do this part, go to the project properties page of the MVC2 project and then the tab "Silverlight Applications". Click "Add" and select your project. Choose the appropriate settings, which should include, at least, debug support.

In order to include your silverlight *.xap file in a view, you just need to reference the file through HTML. I just copy/pasted the section from the automatically generated test page.

 <div id="silverlightControlHost">
    <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
      <param name="source" value="ClientBin/SilverlightApplication1.xap"/>
      <param name="onError" value="onSilverlightError" />
      <param name="background" value="white" />
      <param name="minRuntimeVersion" value="4.0.50401.0" />
      <param name="autoUpgrade" value="true" />
      <a href="http://go.microsoft.com/fwlink/?LinkID=149156&amp;v=4.0.50401.0" style="text-decoration:none">
          <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
      </a>
    </object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>

I placed that into my Views/Home/Index.aspx and my silverlight *.xap application worked as expected.

I hope this helps! =)

greglev
thanks, man. Incidentally my VS 2010 doesn't give me the option to tie it to an MVC 2 project, it just defaults to web forms. Is there a setting where I can change that? I am running Ultimate.
Matt
Well, I think it depends on which project template you select. I'm not sure if the Business and Navigation templates offer a choice, but the basic "Silverlight Application" did. You could just start like I described and then add a Business or Navigation application as a second step. During that step, it should ask if you want to use an existing Web application, since there is one.
greglev
A: 

I tried use SL4 in MVC2 but SL xap file did not load. I got only white background when i was right mose click on backgoround showed me silverlight options option.

I don't know how to run it. Add or change any references ? Or?

Thanks for help. I am sorry for my bad english.

When i add

<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="200px" height="200px">
      <param name="source" value="ClientBin/ZiackaKnizkaSilverLight.xap"/>
      <param name="onError" value="onSilverlightError" />
      <param name="background" value="white" />
      <param name="minRuntimeVersion" value="4.0.50401.0" />
      <param name="autoUpgrade" value="true" />
      <a href="http://go.microsoft.com/fwlink/?LinkID=149156&amp;v=4.0.50401.0" style="text-decoration:none">
          <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
      </a>
    </object>

to masterpage.master i get result what i want but when i put code to any View-page i get nothing.

Peter M.