Here is my ajax call to a partial view once I have done some processing:
function success(data) {
$.ajax({
url: "/Orders/DraftOrderDetailsLineItems",
type: 'GET',
cache: false,
dataType: 'html',
data: { "customerId": data.CustomerId },
success: function (data) {
if (data != "") {
$('#draftOrderItems').html(data);
}
},
error: function (jqXHR, textStatus, errorThrown) {
console.error("[Error in Ajax Request, Get Line Items] Code:" + jqXHR.status + " Error:" + errorThrown + " \nText Status:" + jqXHR.responseText);
}
});
}
On my view I have the following:
<tbody id="draftOrderItems">
@Html.Partial("_draftOrderDetails", Model.Order);
</tbody>
When I am stepping through the code, the draftorder partial view is called and I can see the data filling in the view. However, the page it is hosted on is not "refreshing" the view to show the partial view.
Partial View:
@using System.Linq
@model xxxxxx
@foreach (var lineItem in Model.LineItems)
{
<tr>
<td>
<img src="@Url.Action("GetImage", "ImageBlocks", new { imageID = lineItem.Product.SelfOrDefault().Image.SelfOrDefault().ImageId, Width = 75 })" alt="Thumbnail" />
</td>
<td>
<span title="@(lineItem.Description ?? "")">@(lineItem.Product.ReceiptName ?? "")</span><br />
<span>@lineItem.Product.SKU</span>
</td>
<td>
<span>@lineItem.Product.InventorySummary</span><br />
</td>
<td>@lineItem.Quantity</td>
@if (lineItem.Discount != null ? lineItem.Discount.DiscountCategory != DiscountCategory.ORDER : true)
{
<td>
@lineItem.AdjustedUnitPrice.Value.ToString("C")
<br />(Save @(lineItem.DiscountDisplayValue))
</td>
<td>@lineItem.AdjustedTotalLinePrice.Value.ToString("C")</td>
}
else
{
<td>@lineItem.BaseUnitPrice.Value.ToString("C")</td>
<td>@lineItem.TotalLineBaseValue.ToString("C")</td>
}
</tr>
}
So I know that the ajax is called, the partial view is rendered, but for some reason it is not displaying on the hosting view. Can anyone see something I am missing?
Here is the controller code:
public ActionResult DraftOrderDetailsLineItems (Guid customerId)
{
//lookup cart based on customer ID
var draftOrder = new ComApiCart(customerId,LoggedInUserID);
return PartialView("_draftOrderDetails",draftOrder.OrderDetails);
}
Thanks.
You are just missing the # in the jQuery selector.
$('draftOrderItems').html(data);
should be
$('#draftOrderItems').html(data);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments