I have a CRUD table, and after, for example, each of its edits, I would like to update only the div that contains the table, without updating the entire Index page.

Sample View _Create.chtml

<div class="modal-body"> <h2>Create</h2> <form asp-action="Create"> <div class="form-horizontal"> 

Contoller:

  [HttpPost] public IActionResult Create(Menu cust) { if (ModelState.IsValid) { sMenuRepository.Add(cust); return RedirectToAction("Index", new { fileID = cust.File_Id }); } return View(cust); } 
  • you have ajax tag probably not in vain ... use it - Vitaly Shebanits
  • I understand that I need to use ajax. How to use it in the context of ASP.CORE? Could you give an example? Thank! - troll Bart
  • on the view through the script (jQuery $.ajax(); ) - Vitaly Shebanits

1 answer 1

Coped:

Conroller:

 [HttpGet] public IActionResult ViewCreate() { return PartialView("_Create"); } [HttpPost] public IActionResult Create(Menu cust) { int create_file_id = cust.File_Id; sMenuRepository.Add(cust); return RedirectToAction("ViewTable", create_file_id); } 

Parial View (_Create.chtml):

  <div class="modal-body"> <h2>Create</h2> <form asp-controller="Home" asp-action="Create" data-ajax="true" data-ajax- update="#divPartial" id="#order-form"> ... ... <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal"> Cancel </button> <button type="submit" id="approve-btn" class="btn btn-success"> Save </button> </div> </div> </form> 

Main View:

  <div id="divPartial"> <partial name="_Table" model="Model" /> </div>