Calling a partial view from AJAX

john

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.

nurdyguy

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

MVC Calling a function from a partial view is not working

From Dev

ajax posting from a partial view to controller is null

From Dev

AJAX pagedlist with partial view

From Dev

Not able to refresh the partial view after a form submission from another partial view within it, using ajax in mvc razor

From Dev

How to update parent table from partial view using Ajax

From Dev

Re-render razor partial view returned from AJAX call

From Dev

Best way to pass model from partial view to controller using AJAX?

From Dev

pass a model from partial view to controller by ajax in mvc

From Dev

How to update parent table from partial view using Ajax

From Dev

Getting Value from DropDownList to partial view using Ajax

From Dev

Rendering a partial View with Ajax Unobtrusive

From Dev

Rendering a partial with ajax - missing view

From Dev

jQuery ajax that returns a partial view

From Dev

Rendering a partial View with Ajax Unobtrusive

From Dev

how to login with partial view and ajax?

From Dev

AJAX Model Validation with Partial View

From Dev

print function is calling before partial view

From Dev

print function is calling before partial view

From Dev

AngularJS UI-router, partial views and calling view from browser's location bar

From Dev

MVC Post Form using Ajax (from partial view) but without any redirect (remain on same main view page)

From Dev

Simplest way to get model data/objects in the view from input with an ajax partial view call(s)

From Dev

Update Partial View Within Partial View Using MVC Ajax

From Dev

Update Partial View Within Partial View Using MVC Ajax

From Dev

Calling method from view

From Dev

Calling actionresult from view

From Dev

Return a partial view from a controller?

From Dev

Load partial view from controller

From Dev

returning a partial view from a for loop

From Dev

MVC3: jquery ajax to return partial view with HTML dataType from controller but getting error

Related Related

  1. 1

    MVC Calling a function from a partial view is not working

  2. 2

    ajax posting from a partial view to controller is null

  3. 3

    AJAX pagedlist with partial view

  4. 4

    Not able to refresh the partial view after a form submission from another partial view within it, using ajax in mvc razor

  5. 5

    How to update parent table from partial view using Ajax

  6. 6

    Re-render razor partial view returned from AJAX call

  7. 7

    Best way to pass model from partial view to controller using AJAX?

  8. 8

    pass a model from partial view to controller by ajax in mvc

  9. 9

    How to update parent table from partial view using Ajax

  10. 10

    Getting Value from DropDownList to partial view using Ajax

  11. 11

    Rendering a partial View with Ajax Unobtrusive

  12. 12

    Rendering a partial with ajax - missing view

  13. 13

    jQuery ajax that returns a partial view

  14. 14

    Rendering a partial View with Ajax Unobtrusive

  15. 15

    how to login with partial view and ajax?

  16. 16

    AJAX Model Validation with Partial View

  17. 17

    print function is calling before partial view

  18. 18

    print function is calling before partial view

  19. 19

    AngularJS UI-router, partial views and calling view from browser's location bar

  20. 20

    MVC Post Form using Ajax (from partial view) but without any redirect (remain on same main view page)

  21. 21

    Simplest way to get model data/objects in the view from input with an ajax partial view call(s)

  22. 22

    Update Partial View Within Partial View Using MVC Ajax

  23. 23

    Update Partial View Within Partial View Using MVC Ajax

  24. 24

    Calling method from view

  25. 25

    Calling actionresult from view

  26. 26

    Return a partial view from a controller?

  27. 27

    Load partial view from controller

  28. 28

    returning a partial view from a for loop

  29. 29

    MVC3: jquery ajax to return partial view with HTML dataType from controller but getting error

HotTag

Archive