Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将StudentProfileID和Date Today组合为C#MVC5中Create方法的customID_C#_Entity Framework_Asp.net Mvc 5_Entity Framework 6 - Fatal编程技术网

如何将StudentProfileID和Date Today组合为C#MVC5中Create方法的customID

如何将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

如何结合StudentProfileID和DateToday创建自定义RegNo

StudentProfileID-是在Create方法上自动生成的主键
今日日期-格式: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");
        }