【问题标题】:ASP.NET MVC4 display modes not loading TypeScript outputASP.NET MVC4 显示模式不加载 TypeScript 输出
【发布时间】:2014-01-31 22:39:47
【问题描述】:

我有一个使用 Internet 模板创建的 ASP.NET MVC4 应用程序。在这个项目中,我在 Views/Shared 文件夹中有两个布局文件,_Layout.chsmtl 和 _Layout.Mobile.cshtml。在每个文件中,我都加载了从 TypeScript 编译的不同脚本。在 _Layout.cshtml 我有

<script src="@Url.Content("~/Scripts/app.js?43")" type="text/javascript"></script>

在 _Layout.Mobile.cshtml 中,

<script src="@Url.Content("~/Scripts/MobileApp.js?2")" type="text/javascript"></script>

app.js 和 mobileapp.js 是根据项目文件中的以下设置创建的:

 <Target Name="BeforeBuild">
    <Exec Command="&quot;$(PROGRAMFILES)\Microsoft SDKs\TypeScript\0.8.0.0\tsc&quot; -out scripts\app.js scripts\app.ts -target ES5 @(TypeScriptCompile ->'&quot;%(fullpath)&quot;', ' ')" IgnoreExitCode="true" /> 
    <Exec Command="&quot;$(PROGRAMFILES)\Microsoft SDKs\TypeScript\0.8.0.0\tsc&quot; -out scripts\mobileapp.js scripts\mobileapp.ts  -target ES5 @(TypeScriptCompile ->'&quot;%(fullpath)&quot;', ' ')" IgnoreExitCode="true" />
  </Target>

该应用程序在 Internet Explorer 9 中运行正常。但是,当我在 Opera Mobile 中运行时,似乎没有加载 mobileapp.js,因为它的构造函数只是显示未调用警报。这是 MobileApp.js 的 TypeScript 代码。

 export class MobileApp extends AppBase {                                  

        constructor () { 
            super(null, null)                
              alert("mobile page loading ...?");
        }      
    }

每次我在 Opera Mobile 上刷新索引页面时,我都会在应用程序日志中写入以下消息:

ERROR 2013-01-24 09:39:57,233 172979ms MvcApplication         Application_Error  - ASP.global_asax
System.Web.HttpException (0x80004005): File does not exist.
   at System.Web.StaticFileHandler.GetFileInfo(String virtualPathWithPathInfo, String physicalPath, HttpResponse response)
   at System.Web.StaticFileHandler.ProcessRequestInternal(HttpContext context, String overrideVirtualPath)
   at System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context, AsyncCallback callback, Object state)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

有什么想法吗?

【问题讨论】:

    标签: javascript asp.net-mvc-4 typescript


    【解决方案1】:

    为了让构造函数运行,你必须实例化类。例如:

    var Test = new MobileApp();

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-24
      • 2023-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多