@foreach (var item in Model.policydata)
{
<tr align="center">
<td>
@Html.DisplayFor(modelitem => item.Name)
</td>
<td>
@Html.DisplayFor(modelitem => item.PolicyID)
</td>
<td>
@Html.DisplayFor(modelitem => item.CustomerID)
</td>
<td>
<a onclick="OpenRepositoryFile()" href="@string.Format("http://repository.website.com/{0}/{1}.pdf", Model.PolicyName, item.CustomerID)">View</a>
</td>
</tr>
}
</table>
<script>
function OpenRepositoryFile()
{
var win = window.open('', '_blank');
if(win)
{
//Browser has allowed it to be opened
win.focus();
}else{
//Broswer has blocked it
alert('This application feature requires Popups Enabled. Please right click to open in a new Tab or change your Browser settings');
}
}
</script>
我已獲得此剃刀代碼和此Javascript函數。基本上,Razor鏈接是根據從模型變量中檢索的數據構建的,Javascript功能打開一個新的窗口/選項卡(取決於設置),或者在瀏覽器設置不允許彈出窗口時提醒用戶。單獨使用時,兩者都可以正常工作。在Javascript函數中包含剃刀格式的字符串
繼承人的問題。我希望Razor建立的鏈接作爲Javascript函數的window.open命令中的一個參數。
我想象,在Javascript或JQuery的,會有的String.Format()函數,因爲在淨的,但現在,沒有..
是否存在的一種方式獲取Razor在其標識中通過其ID生成的Href字符串屬性?或有關於此的任何其他建議?
感謝
輝煌的代碼。看着jquery,但我的代碼知識缺乏這個部門,確實需要改進......但是有一個問題。該功能可以正常工作並打開,但即使該選項卡打開,警報也會彈出。這與瀏覽器設置有關嗎?或者可以對代碼做進一步的工作?非常感謝迄今爲止... –