2016-01-21 58 views
0

我研究了爲什麼我們得到「未捕獲的語法錯誤:)參數列表後錯誤」錯誤,我仔細閱讀了一些代碼堆棧溢出的答案。我已經超過了一天,但錯誤仍然存​​在。請幫忙。未捕獲的語法錯誤:)在asp.net mvc應用程序中的參數列表後失蹤javascript

我的代碼

function openinnewtab(filename) { 
    var url = @Url.Action("DisplayDocuments", new { Filename = filename }); 
    var redirectWindow = window.open(url, '_blank'); 
    redirectWindow.location.reload(true); 
    return false; 
} 

我在這裏稱它在我看來,基本上IM特林TTO圖像上實現的onclick功能,從而在單擊圖像時,打開一個新窗口並顯示圖像。

<a onclick="openinnewtab(@filename);"><img title="@filename" src="~/Content/images/image.png"></a> 
+0

檢查我的答案,讓我知道如果這有助於你解決問題。 – ramiramilu

回答

1

基本上你是缺少一些single quotes,你也都在Razor代碼混合JS變量,你的代碼應該是 -

<a onclick="openinnewtab('@filename');"><img title="@filename" src="~/Content/images/image.png"></a> 

而且

function openinnewtab(filename) { 
    var url = '@Url.Action("DisplayDocuments", new { Filename = "tempFileName" })'; 

    // Replace templFileName with actual value which is being passed to this function 
    url = url.replace("tempFileName", filename); 
    var redirectWindow = window.open(url, '_blank'); 
    redirectWindow.location.reload(true); 
    return false; 
} 
+0

哎@ramiramilu謝謝!我錯過了那些單引號。我是一名初學者。在這兩個asp.net n js –

相關問題