2014-01-29 11 views
0

我想補充的查詢字符串這樣的事情如何在window.location中傳遞值?

var id = e.row.cells[0].innerHTML; 
var subTypeId = e.row.cells[1].innerHTML; 

window.location = "/Master/ReceivedStatus?Id=" + '@EncryptDecryptHelper.EncryptString(id)' + "&SubTypeID=" + '@EncryptDecryptHelper.EncryptString(subTypeId)'; 

@ EncryptDecryptHelper.EncryptString總是這樣令人期盼的字符串值,是一個靜態類。

但它顯示錯誤,因爲id和subTypeId在當前上下文中不存在。如果是的話,是否有可能通過這樣的價值呢?

有人請幫助我,告訴我怎樣才能通過這樣的價值。

+0

您是否期望EncryptDecryptHelper正常工作?這看起來像服務器端Razor語法,它生成的JavaScript必須在瀏覽器中執行。 –

+0

我的代碼在View中,並在服務器端傳遞值,EncryptDecryptHelper將在服務器端工作,我將解密Controller中的值 – Rocky

回答

0

我正在使用下面的代碼,它爲我工作。

window.location = '@Url.Action("ReceivedStatus", "Master", new { Id = '@EncryptDecryptHelper.EncryptString(id)', SubTypeID = '@EncryptDecryptHelper.EncryptString(subTypeId)'})'; 
0

變量需要在引號之外;

window.location = '/Master/ReceivedStatus?Id=' + '@EncryptDecryptHelper.EncryptString(' + id + ')&[email protected](' + subTypeId + ')'; 
0

看來你試圖在字符串中使用變量id和subTypeId。您必須轉義字符串才能引用該變量。

window.location = "/Master/ReceivedStatus?Id=" + '@EncryptDecryptHelper.EncryptString(' + id + ')' + "&SubTypeID=" + '@EncryptDecryptHelper.EncryptString(' + subTypeId + ')';