如何保存 2 个学生对象从 .net MVC 应用程序中的一个提交按钮下的表单获取值?
How to save 2 student object getting values from form under one submit button in .net MVC application?
这是代码,控制器代码也在那里This is the Model of Entity Relationship
`public JsonResult 提交(Student_Information stu)
{
db.Student_Information.Add(stu);
db.Student_Information.Add(stu);
db.SaveChanges();}`
<form action="Submit" method="post">
<table class="table table-bordered">
<thead class="thead-light">
<tr>
<th colspan="4">Part A : Student Information</>
</tr>
</thead>
<tbody>
<tr>
<th width="2">Reg No:</th>
<td><input class="form-control" type="text" name="Registration_No" size="30" /></td>
<th width="2">Reg No:</th>
<td><input class="form-control" type="text" name="Registration_No1" size="30" /></td>
</tr>
<tr>
<th>Name</th>
<td><input class="form-control" type="text" name="Name" size="30" /></td>
</tr>
<tr>
<th>Phone</th>
<td><input class="form-control" type="text" name="Phone" size="30" /></td>
</tr>
<tr>
<th>Email</th>
<th><input class="form-control" type="text" name="Email" size="30" /></th>
</tr>
<tr>
<th>
<button class="btn btn-info form-control" name="Submit" value="Submit">Submit</button>
</th>
</tr>
</tbody>
</table>
</form>
public JsonResult Submit(Student_Information stu)
{
db.Student_Information.Add(stu);
db.Student_Information.Add(stu);
db.SaveChanges();
}
这是代码,控制器代码也在那里This is the Model of Entity Relationship
`public JsonResult 提交(Student_Information stu) { db.Student_Information.Add(stu);
db.Student_Information.Add(stu);
db.SaveChanges();}`
<form action="Submit" method="post">
<table class="table table-bordered">
<thead class="thead-light">
<tr>
<th colspan="4">Part A : Student Information</>
</tr>
</thead>
<tbody>
<tr>
<th width="2">Reg No:</th>
<td><input class="form-control" type="text" name="Registration_No" size="30" /></td>
<th width="2">Reg No:</th>
<td><input class="form-control" type="text" name="Registration_No1" size="30" /></td>
</tr>
<tr>
<th>Name</th>
<td><input class="form-control" type="text" name="Name" size="30" /></td>
</tr>
<tr>
<th>Phone</th>
<td><input class="form-control" type="text" name="Phone" size="30" /></td>
</tr>
<tr>
<th>Email</th>
<th><input class="form-control" type="text" name="Email" size="30" /></th>
</tr>
<tr>
<th>
<button class="btn btn-info form-control" name="Submit" value="Submit">Submit</button>
</th>
</tr>
</tbody>
</table>
</form>
public JsonResult Submit(Student_Information stu)
{
db.Student_Information.Add(stu);
db.Student_Information.Add(stu);
db.SaveChanges();
}