当点击“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