logo
Welcome to our new AbleCommerce forums. As a guest, you may view the information here. To post to this forum, you must have a registered account with us, either as a new user evaluating AbleCommerce or an existing user of the application. For all questions related to the older version of Gold and earlier, please go to AbleCommerce Gold forum. Please use your AbleCommerce username and password to Login. New Registrations are disabled.

Notification

Icon
Error

Options
Go to last post Go to first unread
judy at Web2Market  
#1 Posted : Friday, March 3, 2023 8:31:32 AM(UTC)
judy at Web2Market

Rank: Advanced Member

Groups: Developers
Joined: 11/7/2018(UTC)
Posts: 303

Thanks: 21 times
Was thanked: 5 time(s) in 5 post(s)
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).

Wanna join the discussion?! Login to your AbleCommerce Forums forum account. New Registrations are disabled.

shaharyar  
#2 Posted : Thursday, March 16, 2023 4:58:53 AM(UTC)
shaharyar

Rank: Advanced Member

Groups: Admin, Developers, Registered, HelpDesk, Authorized User
Joined: 10/5/2018(UTC)
Posts: 704

Thanks: 5 times
Was thanked: 113 time(s) in 112 post(s)
The following chunk of code is sufficient for the functionality to work. You don't need to add the Move() function and write a onClick listener.
Code:

@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" })



Try commenting out the following line from the code.

Code:
UpdateTargetId = "inbound-listing-container",


This line will actually replace the div content with the data object that is returned from an ajax call. That is the reason the screen turns blank.
judy at Web2Market  
#3 Posted : Thursday, March 16, 2023 11:57:05 AM(UTC)
judy at Web2Market

Rank: Advanced Member

Groups: Developers
Joined: 11/7/2018(UTC)
Posts: 303

Thanks: 21 times
Was thanked: 5 time(s) in 5 post(s)
Thank you, I will try it. This kind of stuff is what I spend hours trying to figure out!
Users browsing this topic
Guest (3)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.