如何将StudentProfileID和Date Today组合为C#MVC5中Create方法的customID
如何结合StudentProfileID和DateToday创建自定义RegNo StudentProfileID-是在Create方法上自动生成的主键如何将StudentProfileID和Date Today组合为C#MVC5中Create方法的customID,c#,entity-framework,asp.net-mvc-5,entity-framework-6,C#,Entity Framework,Asp.net Mvc 5,Entity Framework 6,如何结合StudentProfileID和DateToday创建自定义RegNo StudentProfileID-是在Create方法上自动生成的主键 今日日期-格式:031415 Create方法的示例代码 public ActionResult Create([Bind(Include="StudentProfileID,RegNo,EnrollmentDate,LastName,FirstName,MiddleName,Address,ContactNo,MaritalStatus,Bi
今日日期-格式:031415 Create方法的示例代码
public ActionResult Create([Bind(Include="StudentProfileID,RegNo,EnrollmentDate,LastName,FirstName,MiddleName,Address,ContactNo,MaritalStatus,Birthdate,Birthplace,Age,PositionRank,Years,PRC,SBOOK,MMAP,PPORT,SRC,TraineeType,EndorsedBy,EmergencyPerson,EmergencyAddress,EmergencyContactNo,EmergencyRelationship")] StudentProfile studentprofile)
{
if (ModelState.IsValid)
{
db.StudentProfile.Add(studentprofile);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(studentprofile);
}
我按照本文创建了学生档案
我会感谢你的帮助。谢谢。在db.savechanges()之后;我们将获得sudentProfileId,如下所示
if (ModelState.IsValid)
{
db.StudentProfile.Add(studentprofile);
db.SaveChanges();
int studentId = studentprofile.StudentId;
string custRegNo = studetId.toString()+ DateTime.Now;
return RedirectToAction("Index");
}