當點擊「a」錨標記我想從一個控制器(HomeController.cs)重定向到另一個控制器(CartController.cs)索引[GET]並執行代碼並返回數據到視圖(車/ index.cshtml)。無法呈現按鈕點擊視圖
這裏是js代碼
$(document).on('click', '.btn-margin', function() {
if (parseInt($('#UserID').val()) > 0) {
var pmID = $(this).attr("id"),
bid = $(this).attr("brand-id");
$.ajax({
url: '@Url.Action("index", "cart")',
data: { "id": pmID, "bid" : bid },
type: 'GET',
dataType: 'json',
success: function (response) {
},
error: function (xhr, status, error) {
}
});
}
});
和CartController
[HttpGet]
public ActionResult Index(long id = 0, long bid = 0)
{
GetStates();
return View(productBL.GetProductById(id, bid));
}
正如預期的那樣具有重定向到的車index.cshtml ..但我的結果仍然在指數的HomeController。 cshtml頁面。
請幫我如何獲得預期的結果..
您是否嘗試添加返回RedirectToAction(「Index」,「CartController」);在你的家庭控制器? – ISHIDA
我需要將參數傳遞給該動作 – thiru
試試這個 - 返回RedirectToAction(「Index」,「CartController」,new {id:pmId}) – ISHIDA