如何将记录存储在来自 HttpPost 的列表请求中



如何将发送对象的 HttpPost 请求中的记录存储在列表中

我想存储它从视图中再次处理的每条记录

获取_students对象并将其发送到列表: 列表 dbTempStudentList

在本地处理数据而不依赖于数据库

[HttpPost]public ActionResult Create(Student _student)
{
return View("");
}


public class Student
{
public int StudentID { get; set; }
public string StudentName { get; set; }
public string StudentLastName { get; set; }
public string Creditbalance { get; set; }
public string CurrentBalance { get; set; }
}

我的视图创建

<h2>Create</h2>
<h4>Student</h4>
<hr />
<div class="row">
<div class="col-md-4">
<form asp-action="Create" method="post">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="StudentID" class="control-label"></label>
<input asp-for="StudentID" class="form-control" />
<span asp-validation-for="StudentID" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="StudentName" class="control-label"></label>
<input asp-for="StudentName" class="form-control" />
<span asp-validation-for="StudentName" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="StudentLastName" class="control-label"></label>
<input asp-for="StudentLastName" class="form-control" />
<span asp-validation-for="StudentLastName" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Creditbalance" class="control-label"></label>
<input asp-for="Creditbalance" class="form-control" />
<span asp-validation-for="Creditbalance" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="CurrentBalance" class="control-label"></label>
<input asp-for="CurrentBalance" class="form-control" />
<span asp-validation-for="CurrentBalance" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</form>
</div>
</div>

[HttpPost]
public ActionResult Create(Student _student)
{
var list = (List<Student>)Session["studentList"];
//this is for first time
if(list==null||list.Count()==0) list = new List<Student>();
list.Add(_student);
Session["studentList"]=list;
return View();
}

最新更新