Hi
i've use this external javascript function to access ViewData variable(s) :
function deleteOrderItem(orderID) { if (confirm('Are you sure want to delete this item?')) {$.ajax({ type: "POST", url: "DeleteOrder", data: { id: orderID }, success: function () { setTimeout(function () { debugger; var personID = "@ViewData['_personID']"; viewItem(personID); }, 500) } }); } }
But at runTime, when i'm using developer tools, the personID contains @ViewData[_personID] as text and not accessing real viewData which i've set in my action method!
Here is my action method :
// POST: Orders/Delete/5 [HttpPost] public async Task<IActionResult> DeleteOrder(int id) { var orders = await _dbContext.Orders.FindAsync(id); ViewData["_personID"] = orders.PersonId; _dbContext.Orders.Remove(orders); await _dbContext.SaveChangesAsync(); return RedirectToAction(nameof(Index)); }
Where is the problem & how to solve it?
Thanks in advance