【问题标题】:asp.net Javascript window.location Url.Action not workingasp.net Javascript window.location Url.Action 不起作用
【发布时间】:2017-09-20 01:37:24
【问题描述】:

我尝试让 JavaScript 在 ASP.NET 中工作 我的 JavaScript:

 function reportOrder(sender, args) {
    alert("Message");

    window.location.href = @Url.Action("StartReport", "PrintOut", New With {.Area = "Printing", Key .ReportName = "Test",
                                                    Key .typeOfReport = TypeOfPrintingIS.Order,
                                                    Key .CompanyId = DirectCast(ViewData("CompanyId"), Guid),
                                                    Key .ExchangePrintData = CType(locOrderReport, ExchangeData.IExchangePrintData)});

}

首先,该功能有效,当我禁用 window.location 时,会引发警报!所以,问题必须在@UrlAction(

此外,Area 正在工作,因为当我使用类似的 Html.RenderAction 函数和另一个函数的另一个指令时,它工作正常。

Controller 内的功能:

 <HttpPost>
    Function StartReport(ReportName As String, typeOfReport As TypeOfPrintingIS, CompanyId As Guid, ExchangePrintData As Code.ExchangeData.IExchangePrintData) As ActionResult
        Dim model As New HTML5ViewerModel()
        model.ViewerOptions.UseUIMiniStyle = True
        locReportHelper.CompanyId = CompanyId
        locReportHelper.ReportName = ReportName
        locReportHelper.TypeOfReport = typeOfReport
        locReportHelper.ExchangePrintData = ExchangePrintData
        model.ReportName = locReportHelper.CreateReportId

        Return View("Html5Viewer", model)
    End Function

而“IExchangePrintData”接口是一个空接口,用于验证类是否正确。

你们中有人有想法吗? 非常感谢 - 周末愉快

【问题讨论】:

  • 使用@Url.Action时浏览器控制台中是否有任何错误?

标签: javascript c# asp.net vb.net


【解决方案1】:

尝试用单引号将您的 razor 指令括起来。看起来像这样:window.location.href = '@Url.Action("SomeActionName", "SomeControllerName", etc...)';
猜猜这应该可行,因为你提到@Html.RenderAction 工作正常。

【讨论】:

  • 非常感谢! - 这就是魔法钥匙!
猜你喜欢
  • 2016-12-16
  • 1970-01-01
  • 2019-02-03
  • 2012-11-21
  • 2021-08-19
  • 1970-01-01
  • 2015-04-14
  • 2012-02-07
  • 1970-01-01
相关资源
最近更新 更多