简体   繁体   中英

OnSubmit = false triggering another form on the page

I have 2 forms on the same MVC page. They look like this :

    @using (Html.BeginForm("InstructionSearch", "Search", FormMethod.Post, new { }))
        {
        }        

and

    @using (Html.BeginForm("ECN", "Search", new { id = "searchForm", onsubmit = "return checkFormEcn()" }))
        { 
        }

They're following each other in the code, so, no nest here ;)

So, i'd like to prevent the second one (With "ECN"), from beeing submited when my checkFormEcn returns false.

This is alright, but when the 2nd form's submit is denied by my javascript function, my first form (With "Search") is automatically submitted, without touching anything.

Any idea of how i could prevent this ?

If you also don't want the first form to submit when the second one doesn't submit then add this to the first form:

onsubmit = "return checkFormEcn()"


@using (Html.BeginForm("InstructionSearch", "Search", FormMethod.Post, new { onsubmit = "return checkFormEcn()" }))
{
}        

i think u can easy have HTML button outside the form and onclick event you submit form

search

@using (Html.BeginForm("ECN", "Search", new { id = "searchForm" })) {

}

same as InstructionSearch form

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM