I have multiple forms on a single razor page that I want to be POSTed after one button is clicked. I tried using a javascript function that would .submit() both forms (put in the onclick= of the button), but only one form's values were actually passed to the OnPost() method serverside. Here's the relevant code from the .cshtml and the .cs files:
StudentMain.cshtml
<!--first form-->
<form class="login100-form" method="post">
<span class="login100-form-title" style="padding-bottom: 38px">
Student Information
</span>
<div class="wrap-input100">
<input class="input100 has-val" type="text" name="name" value='@ViewData["name"]' readonly/>
<span class="focus-input100" data-placeholder="Student Name"></span>
</div>
...more divs/inputs as above
</form>
<!--second form-->
<form class="login100-form" method="post">
<div class="wrap-input100">
<select class="input100 select" name="eduplan" selectedval='@ViewData["eduplan"]'>
<option disabled selected value style="display:none"/>
<option>High School Diploma</option>
<option>Technical Training</option>
<option>Associate Degree</option>
<option>Bachelor's Degree</option>
<option>Advanced Degree</option>
<option>Military</option>
<option>Other</option>
</select>
<span class="focus-input100" data-placeholder="Education Plan"></span>
</div>
...more divs/selects as above
<div class="container-login100-form-btn">
<div class="wrap-login100-form-btn">
<div class="login100-form-bgbtn"></div>
<button class="login100-form-btn" type="submit">
Save
</button>
</div>
</div>
</form>
StudentMain.cshtml.cs
public class StudentMain : PageModel
{
public void OnPost(string eduplan, string college, string major, string careerpath, string ethnicity, string gender, string ncaa, string firstgen, string onlineinterest)
{
Database.SaveStudentData(eduplan, college, major, careerpath, ethnicity, gender, ncaa, firstgen, onlineinterest);
}
}
So, what's the best way to go about doing this? How can I make sure that the values from both forms are passed to the OnPost() method simultaneously? Do I need to use AJAX in some capacity? Any help is appreciated.