Popup Form with multiple submit buttons
I want to create popup form with multiple submits (use
formaction
).
If i create popup with InitPopupForm, than formaction ignored and submit always send to action from
<form asp-action="" asp-controller="Reports">Buttons always send to Reports/Index. If i create popup with InitPopup, formaction work correctly, but here is problem with validation.
@using (Html.Awe().BeginContext())
{
@Html.EditorFor(a => a.DateFrom)
@Html.EditorFor(a => a.DateTo)
@Html.EditorFor(a => a.Login)
<button asp-action="AnotherAction1" asp-controller="Reports">Report1</button>
<button asp-action="AnotherAction2" asp-controller="Reports">Report2</button>
}
</form>
return PartialView("Index", model);redirects to page instead of replacing the popup content.
Evgeny Alekseev
asked
at 01 Oct 2021
Answers
-
The PopupForm OK/submit button will post the first form it finds inside the popup, and the form will be posted to it's action attribute ( generated html action attribute ). When you use the simple Popup there's no js code preventing the native submit. You could set
.UseDefaultButtons(false)
on the PopupForm and add your own buttons using.Button("Submit", "submit1")
and in the js function for the button you could set the form's action attribute before submit<div id='form1'>
<form>
...
</form>
</div>
function submit1(){
$('#form1 form').attr('action', '@Url.Action("Action123")').submit();
}Omuanswered at 01 Oct 2021