I am trying to update a partial view in ASP.NET MVC with an ajax form contained within the partial view. However whenever the form is submitted the entire page changes to the partial view, not just the part of the page where the partial view is contained.
My partial View Form:
@using (Ajax.BeginForm("Archive", "Products", new { id = note.ID },
new AjaxOptions { HttpMethod = "POST", InsertionMode = InsertionMode.ReplaceWith,UpdateTargetId = @*Unique ID*@ }))
{
@Html.AntiForgeryToken()
<input type="submit" value="Archive" class="btn btn-default"/>
}
The Function It Calls:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Archive(int ID)
{
ProductNote model = db.ProductNotes.FirstOrDefault(x => x.ID == ID);
model.Archived = true;
db.SaveChanges();
Product modelP = db.Products.FirstOrDefault(z => (z.ProductNotes.FirstOrDefault(y => y.ID == model.ID).NoteText != null));
System.Diagnostics.Debug.WriteLine(modelP.ID.ToString() + "Test Test 123");
System.Diagnostics.Debug.WriteLine("Test\n\n\n");
return PartialView("_ProductNotes", modelP);
}