【问题标题】:How to save 2 student object getting values from form under one submit button in .net MVC application?如何在 .net MVC 应用程序的一个提交按钮下保存 2 个学生对象从表单中获取值?
【发布时间】:2020-03-22 00:09:44
【问题描述】:

这是代码,控制器代码也在那里This is the Model of Entity Relationship

`public JsonResult Submit(Student_Information stu) { db.Student_Information.Add(stu);

        db.Student_Information.Add(stu);




        db.SaveChanges();}`

【问题讨论】:

  • public ActionResult Signup(student student) { try { using (StudentsEntities db = new StudentsEntities()) { db.students.Add(student); db.SaveChanges(); // TODO: 在此处添加插入逻辑 return RedirectToAction("Signin"); } } 捕捉 { 返回视图(); } }

标签: sql asp.net-mvc database sql-server-2005


【解决方案1】:

<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();

}

【讨论】:

  • 这不起作用,因为 ID 不重复,并且在 sql 中,每条记录都有一个唯一的元组
猜你喜欢
  • 2014-01-31
  • 2020-07-15
  • 2014-01-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多