2017-04-23 40 views
0

我試圖讓一個JavaScript中的ASP.NET 工作我的javascript:asp.net的JavaScript window.location的Url.Action不工作

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)}); 

} 

首先,函數工作,當我關閉窗口。地點,警報提出!所以,這個問題已經成爲@UrlAction(

而且也,該地區工作,因爲,當我使用了類似的Html.RenderAction功能與​​其他指令給另一個函數,它工作正常範圍內。

控制器內的功能:

<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」接口是一個空的接口,以驗證正確的類

是否有人對你有一個想法 THX很多 - 有一個很好的?周end

+0

使用'@ Url.Action'時瀏覽器控制檯中的任何錯誤? – Ryan

回答

0

嘗試用單引號包裝您的剃鬚刀指令。它看起來像這樣:window.location.href = '@Url.Action("SomeActionName", "SomeControllerName", etc...)';
猜猜這應該工作,你提到的原因@Html.RenderAction工作正常。

+0

THX很多! - 這是魔術鍵! –

+0

不客氣。 – Ryan