Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 609727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:35:50+00:00 2026-05-13T17:35:50+00:00

I am rendering out a partial view like so: <div id=cart> <%Html.RenderPartial(Cart, Model); %>

  • 0

I am rendering out a partial view like so:

    <div id="cart">
    <%Html.RenderPartial("Cart", Model); %>
</div>

For each line in the cart I am using a form to remove items (it is important that this works when javascript is disabled hence no Ajax.ActionLink):

    <%using (Ajax.BeginForm("RemoveFromCart", "Cart", new AjaxOptions { UpdateTargetId="cart"}))
  {%>                           
        <%=Html.Hidden("ProductId", line.Product.Id)%>
        <%=Html.Hidden("returnUrl", ViewData["returnUrl"])%>
        <input type="image" src="<%=AppHelper.ImageUrl("delete.gif")%>" value="Remove item"  />
<%} %>

And my controller action:

        [HttpPost]
    public ActionResult RemoveFromCart(Cart cart, int productId, string returnUrl)
    {
        Product p = _catalogService.GetProduct(productId);
        cart.RemoveLine(p); // TODO - what about if null?

        if (Request.IsAjaxRequest())
            return PartialView("Cart", cart);
        else
            return RedirectToAction("Index",  new { returnUrl });
    }

From my understanding, with javascript enabled, clicking the remove button will make an async post to the action and replace the contents of the “cart” container with the updated partial view. If js is disabled, a full postback is made and the user is redirected to the index page once more.

If I add a few items to the cart and delete an item it works fine. However, if I then attempt to delete another item nothing happens. The reason for this is that looking at the page source following the successful delete, the hidden field containing the product id to remove is showing the id of the item already deleted.

Before successful delete:

<input id="ProductId" name="ProductId" type="hidden" value="6" />
<input id="ProductId" name="ProductId" type="hidden" value="22" />
<input id="ProductId" name="ProductId" type="hidden" value="47" />

After removing the third product (47) the remaining items display a hidden field of value 47. My model has certainly updated as I can see that the item is removed when stepping through the controller action but it as if my partial view is not binding properly.

Any help would be appreciated.

Thanks
Ben

  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T17:35:51+00:00Added an answer on May 13, 2026 at 5:35 pm

    Put your product id in the route values for the form extension instead of a hidden field. I think that will avoid the problem entirely.

    <%using (Ajax.BeginForm("RemoveFromCart", "Cart", new { id = line.Product.Id }, new AjaxOptions { UpdateTargetId="cart"}))
      {%>                           
            <%=Html.Hidden("returnUrl", ViewData["returnUrl"])%>
            <input type="image" src="<%=AppHelper.ImageUrl("delete.gif")%>" value="Remove item"  />
    <%} %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am rendering out a ViewUserControl (.ascx file) in a view: <% Html.RenderPartial(Comments, Model.Comments);
I have just started using Html.RenderPartial(usercontrol, model) to render my user controls. Is it
I'm having trouble rendering out a template, my data looks like this: var data
I can not figure out why my rich:dataTable is not rendering. I am using
I have a partial view: <%@ Control Language=C# Inherits=System.Web.Mvc.ViewUserControl<DomainModel.Entities.Product> %> <div class=item> <h3><%= Model.Name
I am rendering a menu from a Partial Action directly to the layout, using:
I have some HTML that I am rendering out to a PDF file with
I am trying to work out what is going on with regards to rendering
I'm rendering a DropDownList in my Visual Studio 2005 ASP.NET code behind page out
Rendering the same html in IE and Firefox gives me a different result because

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.