Skip to content

REFRESH A PARTIAL VIEW WITHOUT LOADING THE WHOLE VIEW

Souhaile Safouani

Asked Jun 29, 2014, 2:45 AM EDT1 answer
Share
LinkedInX
hi,
well , i have an e-commerce app, when i click at "add to cart" button , i want that this article is added to cart without loading this page.
I know , i have to work with ajax, i did that, but when i click into the button , nothing appears in the cart, but when i load manually the view , i see the article added,
this is the structure of my app
1/_layout.cshtml : call 2 another views :
1-1/_cartshop.cshtml : contains the cart
1-2/index.chstml , contains the list of articles , also contains the ajax button

this is my method in homecontroller :
public PartialViewResult addtocart(int id)
 {
 // article added to the list
  return PartialView("_cartshop");
}

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Hello,

    You have use following ajax link button and put your partial view under the divtarget 

    @Ajax.ActionLink("Link Text", "ActionMethod", "Controller", new AjaxOptions{UpdateTargetId="divtarget ",HttpMethod = "Post" , InsertionMode = InsertionMode.Replace })
    0