Welcome to deBUG.to Community where you can ask questions and receive answers from Microsoft MVPs and other experts in our community.
2 like 0 dislike
563 views
in .Net Framework by 64 69 85

I have muiltiple forms on single razor page, and I want to add these Forms in one Form with muiltple POST function in the behind code on Razor page.

AddEdit.cshtml.cs

@* first form *@
<form method="Submit">

    <div asp-validation-summary="ModelOnly" class="alert alert-danger"></div>

	<input asp-for="ID" />
	<input asp-for="Password"/>
                             
    <input type="submit"  value="Submit" />

</form>

@* second form *@
<form method="CheckStatus" >

     <input type="submit" value="Check Status" />

</form>

 

How to use multiple onPOST in single form element?


1 Answer

2 like 0 dislike
by 64 69 85

Muiltiple POSTs in single Form Razor Pages

You can use different POST methods in single Form by adding asp-page-handler attribute with value of method name in input submit:

  • asp-page-handler="Submit"

The UPDATED code that specified in the question can be found Below:

<form method="post">

    <div asp-validation-summary="ModelOnly" class="alert alert-danger"></div>

	<input asp-for="ID" />
	<input asp-for="Password"/>
	
    // This will call OnPostSubmit() in the behind code                         
    <input type="submit" value="Submit" asp-page-handler="Submit" />
	
	// This will call OnPostCheck() in the behind code   
	<input type="submit" value="Check Status" asp-page-handler="Check"/>
	
</form>
If you don’t ask, the answer is always NO!
...