所以我有一個下拉列表在我的瀏覽歷史:ASP.NET MVC4 +下拉列表+ JS的onChange事件
@Html.DropDownList("ddlAccounts", null, new { @onchange="onChange(this.value);" })
,我有這個js事件替換URL ../History/到../History/2,../History/5
function onChange(value) {
window.location.href = value;
}
相反,它總是將值添加到當前url。因此,例如在更改下拉菜單中的索引後,我得到History/2/5。
它不需要用「@」在htmlAttributes字典onchange屬性添加,僅在c#中使用前綴作爲關鍵字的屬性,例如@class –