Embedding a Silverlight App into a MVC

2019-08-06 22:45发布

I decided to convert the WPFs into a Silverlight applications. My only problem is trying to get it to display the silverlight application in my MVC web browser. I added all of my silverlight projects into my MVC project. I am just not getting it to show my silverlight application. Can someone tell me what I am doing wrong in my asp part in my CSHTML

<h2>System</h2>
 <asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
  <div id="silverlightControlHost">
     <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="1000" height="800">
        <param name="source" value="/ClientBin/System.xap" />
        <param name="onError" value="onSilverlightError" />
        <param name="background" value="white" />
        <param name="minRuntimeVersion" value="5.0.61118.0" />
        <param name="autoUpgrade" value="true" />
        <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=5.0.61118.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>
</asp:Content>

I even tried to get the full source path from the root folder of the project I added.

<param name="source" value="/System/System.Web/ClientBin/System.xap" /> 

It still won't display the silverlight application.

The other thing I notice is runat="server", the runat has a green underline and says:

ASP.NET attributes are only allowed in ASP.NET files.

I don't know if it is suppose to do that or not.

I got how to embed a Silverlight into a MVC from here

2条回答
兄弟一词,经得起流年.
2楼-- · 2019-08-06 23:00

Do you have the Silverlight project added to your MVC project? If you don't you will need to go to your project that is your MVC, right click it and go to properties. Go to silverlight applications then add the project there too. Then try it with your current code in place and see if that works.

查看更多
beautiful°
3楼-- · 2019-08-06 23:03

Although it is technically possible to embed WPF inside a website in the form of a Silverlight application, but this should be prevented where possible, see 8 reasons to avoid Flash (or Silverlight) like the plague when designing a website. This and this are also a good read.

Silverlight apps also run in a sandboxed environment, meaning each "page" in your situation will be a different "application". You still will have to rewrite and implement web specific controllers and views to host each Silverlight component. It is advised to consider a rewrite.

查看更多
登录 后发表回答