开发者

All Silverlight Examples use WebForms. Are there tutorials for use with MVC 2?

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 g开发者_运维百科et it started but how do I get the .xap to show in the View? Looking for a good tutorial or blog?


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&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! =)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜