I have a view with a partial view listing some items.
After entering selections, the user clicks Move and that moves the item from one location entity to another. This is working, but I always have trouble showing a success/error message to the user and updating the display also. The toastr message shows, but the page is blank after the move.
Thanks
Think of a listing similar to an item listing on an order, only with a move button and a dropdown to select the shipment to move it to.
The main view has a dropdown to select a location, and when a location is selected, it lists all the items currently in that location
<div id="inbound-listing-container">
@Html.Action("_InboundItemsListing", new { SelectedLocationId = 0 })
</div>
The button in the item in the grid in the partial view is like this:
@Ajax.ActionLink("Move", "MoveItemLocation", "InventoryModule", new { itemId = item.Id, locationId = item.LocationId,id=string.Format("Move_{0}",item.Id)}, new AjaxOptions()
{
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "inbound-listing-container",
LoadingElementId = "loader",
HttpMethod="POST"
}, new { @class = "btn btn-sm btn-white",onclick="Move(this)" })
The Move method is at the bottom of the main view and this is the code:
function Move(obj) {
var actionUrl = obj.href;
var url = actionUrl.slice(actionUrl.indexOf('?') + 1).split('&');
var itemId = GetParameterValues('itemId', url);
var qtyId = '#MoveQuantity_' + itemId;
var moveQty = $('#MoveQuantity_' + itemId).val();
var newLocationId = $('#Location_' + itemId).val();
$.ajax({
url: "MoveItemLocation",
type: "POST",
data: {"itemId":itemId,"quantity":moveQty,"newLocationId":newLocationId},
success: function (data) {
if (data.success == true) {
toastr.success("Item Moved Successfully", "Success");
// location.reload(true);
}
if (data.success == false) {
toastr.error(data.message, "Error", {timeout:180000});
}
initAbleGrid();
// $("#inbound-listing container").html(data);
},
});
}
The controller returns messages like return Json(new { success = true, message = "Moved", JsonRequestBehavior.AllowGet });
Image shows what the page looks like.
Thanks
2023-03-03_9-29-06.png
(41kb) downloaded 4 time(s).