简体   繁体   English

如何将Silverlight应用程序放入ASP MVC视图页面?

[英]How can I put a Silverlight Application into a ASP MVC view page?

I'm working with both silverlight and asp mvc. 我正在使用silverlight和asp mvc。 The silverlight application performs a page request, and it works fine (into the test page generated by the VS), but I can't find a way to put it into my view. silverlight应用程序执行页面请求,它工作正常(进入VS生成的测试页面),但我找不到将其放入视图的方法。

MiniSIG MiniSIG

<div id="silverlightControlHost"> 

    <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">


      <param name="source" value="/ClientBin/MiniSIG.xap"/>
      <param name="onError" value="onSilverlightError" />
      <param name="background" value="white" />
      <param name="minRuntimeVersion" value="3.0.40818.0" />
      <param name="autoUpgrade" value="true" />
      <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40818.0" style="text-decoration:none">
          <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
      </a>
    </object>

</div> 

I tried almost everything (from putting the whole thing in the Site.Master page to loading the Silverlight.js from there). 我尝试了几乎所有的东西(从将整个东西放入Site.Master页面到从那里加载Silverlight.js)。 Can anywone give me some advice on how should I do this? 我能不能就如何做到这一点给我一些建议?

My view now looks like: 我的观点现在看起来像:

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2>MiniSIG</h2>

    <div id="silverlightControlHost"> 

        <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">


          <param name="source" value="/ClientBin/MiniSIG.xap"/>
          <param name="onError" value="onSilverlightError" />
          <param name="background" value="white" />
          <param name="minRuntimeVersion" value="3.0.40818.0" />
          <param name="autoUpgrade" value="true" />
          <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40818.0" style="text-decoration:none">
              <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
          </a>
        </object>

    </div> 

</asp:Content>

And my Site.Master: 和我的Site.Master:

<head runat="server">
    <title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>
    <link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
     <style type="text/css">
    html, body {
        height: 100%;
        overflow: auto;
    }
    body {
        padding: 0;
        margin: 0;
    }
    #silverlightControlHost {
        height: 100%;
        text-align:center;
    }
    </style>
    <script type="text/javascript" src="Silverlight.js"></script>
    <script type="text/javascript">
        function onSilverlightError(sender, args) {
            var appSource = "";
            if (sender != null && sender != 0) {
                appSource = sender.getHost().Source;
            }

            var errorType = args.ErrorType;
            var iErrorCode = args.ErrorCode;

            if (errorType == "ImageError" || errorType == "MediaError") {
                return;
            }

            var errMsg = "Unhandled Error in Silverlight Application " + appSource + "\n";

            errMsg += "Code: " + iErrorCode + "    \n";
            errMsg += "Category: " + errorType + "       \n";
            errMsg += "Message: " + args.ErrorMessage + "     \n";

            if (errorType == "ParserError") {
                errMsg += "File: " + args.xamlFile + "     \n";
                errMsg += "Line: " + args.lineNumber + "     \n";
                errMsg += "Position: " + args.charPosition + "     \n";
            }
            else if (errorType == "RuntimeError") {
                if (args.lineNumber != 0) {
                    errMsg += "Line: " + args.lineNumber + "     \n";
                    errMsg += "Position: " + args.charPosition + "     \n";
                }
                errMsg += "MethodName: " + args.methodName + "     \n";
            }

            throw new Error(errMsg);
        }
    </script>

</head>

I can't see any problem here, the div names are the same. 我在这里看不到任何问题,div名称是相同的。

One mistake I see is that you should have a forward slash before the ClientBin folder... 我看到的一个错误是你应该在ClientBin文件夹之前有一个正斜杠...

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

Also, I'd include this code to ensure Firefox compatibility: 此外,我将包含此代码以确保Firefox兼容性:

<style type="text/css">     
#silverlightControlHost
{
  height: 100%;
}
</style>

<div id="silverlightControlHost"> 
  <!-- Silverlight object goes here -->
</div> 

(Otherwise the Silverlight app will be collapsed and invisible in Firefox.) (否则Silverlight应用程序将在Firefox中折叠并隐藏。)

我使用Steve Wortham给出的一半解决方案解决了这个问题:我没有输入100%,而是键入480px,这是我的Silverlight应用程序的大小,现在也适用于Firefox。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何响应需要访问视图中数据的 ASP.NET MVC 应用程序页面上的事件? - How can I respond to events on a page in an ASP.NET MVC app that need to access data within the View? 如何在浏览器中不打开页面的情况下自动运行 asp.net mvc 应用程序 - How can i auto run asp.net mvc application without open page in browser 如何在一个ASP MVC项目中拥有多个Silverlight应用程序? - How to have more than one silverlight application in an ASP MVC project? 我无法在 ASP.NET MVC 5. 应用程序的视图中转换我的日期时间格式。 我该如何解决? - I can't convert my datetime format in the View of a ASP.NET MVC 5. Application. How do I solve it? 如何部署Silverlight 4应用程序 - how can I deploy my silverlight 4 application 我如何重定向一个ASP.NET MVC2页面 - How can I redirect an asp.net mvc2 page 如何重定向到ASP.NET MVC 3中的错误页面? - How can I redirect to an error page in asp.net mvc 3? 如何查看保存到MVC Web应用程序中文件流的图片? - How can I View a picture saved to a filestream in an MVC web application? 我如何自动刷新MVC4上的“查看”页面 - how can i refresh automaticly View page on MVC4 我如何将一个简短的 ASP.NET WebForms 应用程序迁移到 ASP.NET MVC 应用程序? - How i can migrate a short ASP.NET WebForms Application to ASP.NET MVC Application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM