In my code, i use ajax.beginform for collection entries (with modal window for new entries) then refresh the list.
Controller
public ActionResult BusinessCategoryNewUpdateRow(BusinessCategoryViewModel vmodel)
{
try
{
vmodel.Subcategories.Add(vmodel.NewEditEntry);
return PartialView("BusinessCategory/SubBusinessCategoryView", vmodel);
}
catch
{
return View();
}
}
View :
@using (Ajax.BeginForm("BusinessCategoryNewUpdateRow", "BusinessReference", new AjaxOptions
{ UpdateTargetId = "subCategoryPart", OnSuccess = "clearDialog" }, new { id = "showWin" }))
{
@Html.LabelFor(model => model.MainCategory.name, new { @class = "floating-label" })
@Html.EditorFor(model => model.MainCategory.name, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.MainCategory.name, "", new { @class = "text-danger" })
@Html.LabelFor(model => model.MainCategory.business_cat_code, new { @class = "floating-label" })
@Html.EditorFor(model => model.MainCategory.business_cat_code, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.MainCategory.business_cat_code, "", new { @class = "text-danger" })
@Html.LabelFor(model => model.MainCategory.description, new { @class = "floating-label" })
@Html.EditorFor(model => model.MainCategory.description, "Text", new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.MainCategory.description, "", new { @class = "text-danger" })
Sub-Category
@**@
@*popup window*@
@*popup window*@
@Html.Partial("BusinessCategory/SubBusinessCategoryView", Model)
}
This part is ok, the problem is when i include/add Html.BeginForm outside Ajax.BeginForm, the add button of modal window triggers the Html.BeginForm instead of the Ajax.BeginForm.
What is the best approach to handle collections (parent-child entries) then perform a final submit using Html.BeginForm and Ajax.BeginForm?
Is there a similar code snippet to cater parent-child entries?
Tuhin PaulPosted Nov 10, 2023, 9:03 AM
view code:
JS code:
The JavaScript code handles the AJAX submission of child entries and updating the display of child entries without a full page reload.