I have index view, that have list of products in partialview, with Edit and Delete buttons. Edit button call 2nd level Edit partialview. There is button to launch update, but it works anyway as Http post ActionResult even as void and with [NonAction] attribute. It is probably due to that Edit partial view loads as Get Action, and so any button in it, that sends updates to db, work as Post Action. And there is no way now to return this update method except either index or edit.cshtml!
ProductController:Controller ...
//Get Edit
public PartialViewResult Edit(int id)
{
var product = productRepo.GetProduct(id);
return PartialView("_Edit", product);
}
[NonAction] //Public or private all return "_Edit" partialview
void Edit(Product product)
{ //ActionResult Edit(Product product)
try
{
productRepo.UpdateProduct(product);
//return new EmptyResult();
//return PartialView();
}
catch
{
//return PartialView("_Edit");
}
}
_Edit partial view:
<script>
$(document).ready(function () {
$("#updateProduct").click(function () {
$("#updateProduct").parent().parent().parent()
.find("#allProducts").load('/Shared/_ShowAll');
// .load('@Url.Content("/Shared/_ShowAll")')
});
});
//By clicking update button it should load new version of allProducts DIV with _ShowAll partial view after product update (or delete)
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Product</legend>
@Html.HiddenFor(model => model.Id)...
........
<p>
<input id="updateProduct" type="submit" value="Update" />
</p>
What I can to do to run productRepo.UpdateProduct(product);
as
non-action method without loading partialview as full-page mainview? And then call Jquery .load('/Shared/_ShowAll')
in upper-level view that should be possible. The only hardly semi-solution is to redirectToAction("Index")
, but it reload mainview, and all partialview got rolled up. An then I need to open ListofProduct partialview additionally. What other options is for my approach of CRUD SPA with PartialViews in ASP.NET MVC?
But after clicking ActionLink - no result. Nothing change in view and updating product??? – art May 28 '20 at 20:30