2 回答

TA貢獻1772條經驗 獲得超6個贊
你可以這樣寫錨標簽-
<a id="@c.Key" href ="javascript:void(0);" onclick="postBrands(@c.Key)">@c.Key</a> //replace postBrands with desired function name
然后在 javascript 中定義將包含發布請求的函數-
function postBrands(key) {
$.ajax({
type: 'POST',
url: '@Url.Action("/brandsOfACategory")',
contentType: 'application/json; charset:utf-8',
data: JSON.stringify({ id: key })
})
}

TA貢獻2012條經驗 獲得超12個贊
您可以輸入 href 然后href在客戶端點擊代碼中獲?。?/p>
<a id="@c.Key" href ="@Url.Action("actionName","controllerName")">@c.Key</a>
在點擊事件中,您可以編寫以下內容:
$(document).on('click', 'a', function () {
var Url = $(this).attr("href"); // get href value
$.ajax({
type: 'POST',
url: Url, // use it here
contentType: 'application/json; charset:utf-8',
data: JSON.stringify({ id: this.id })
})
- 2 回答
- 0 關注
- 121 瀏覽
添加回答
舉報