Can you just update a partial view instead of full page post?

后端 未结 5 1652
清酒与你
清酒与你 2020-12-23 17:04

Is there a way to submit a partial view form in asp.net mvc without reloading the parent page, but reloading the partial view only to its new state? Similar to how knockout.

5条回答
  •  情歌与酒
    2020-12-23 17:20

    As normal what I find when looking for things like this is people give too limited information so I will attempt to help here. The key is to set up a div with an ID you can append the return html to. Also when hitting your controller make sure it returns the partial. There are some potential problems with this method but on a good day it should work.

    @{ Html.RenderPartial("WidgetCategories.cshtml"); }
    function DeleteCategory(CategoryID) { $.get('/Dashboard/DeleteWidgetCategory?CategoryID=' + CategoryID, function (data) { if (data == "No") { alert('The Category has report widgets assigned to it and cannot be deleted.'); } else { $('#CategoryList').html(data); } } ); } [HttpGet("DeleteWidgetCategory")] [HttpPost("DeleteWidgetCategory")] public IActionResult DeleteWidgetCategory(string CategoryID) { string Deleted = CategoryModel.DeleteCategory(CategoryID); if (Deleted == "Yes") { return PartialView("WidgetCategories"); } else { return this.Json("No"); } }

提交回复
热议问题