如何在ASP.NET MVC中的录取表格成功页面上显示来自模型的id



我制作了一份录取表格,所以在提交表格后,它会重定向到另一个名为";成功;在那里,我想显示每个提交的录取表格的学生id或主要id,它是在模型中生成的,我的代码如下:

型号

public class AdmissionModel
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Std_id { get; set; }  <-- **THIS I want to show in success page** -->
[Required]
[StringLength(50)]
public string std_name { get; set; }
[Required]
[StringLength(50)]
public string std_father { get; set; }
[Required]
[StringLength(50)]
public string std_mother { get; set; }
[Required]
[DataType(DataType.Date)]
public string DOB { get; set; }
public string std_gender { get; set; }
[Required]
[StringLength(200)]
public string R_address { get; set; }
[Required]
[StringLength(200)]
public string P_address { get; set; }

public string adm_for { get; set; }
[Required]
public string university { get; set; }
[Required]
public string E_no { get; set; }
[Required]
public string Center { get; set; }
[Required]
public string City { get; set; }

public string Field { get; set; }
[Required]
public string Marks_secured { get; set; }
[Required]
public string out_of { get; set; }
[Required]
public string Class_obtained { get; set; }
[Required]
public string Sports_details { get; set; }
public string adm_status { get; set; }
}

控制器:

public class AdmissionController : Controller
{
contextclass db = new contextclass();        
public ActionResult Admission()
{
return View();
}

[HttpPost]
public ActionResult Admission(AdmissionModel adm)
{
AdmissionModel a = new AdmissionModel();
a.std_name = adm.std_name;
a.std_father = adm.std_father;
a.std_mother = adm.std_mother;
a.DOB = adm.DOB;
a.std_gender = adm.std_gender;
a.R_address = adm.R_address;
a.P_address = adm.P_address;
a.adm_for = adm.adm_for;
a.university = adm.university;
a.E_no = adm.E_no;
a.Center = adm.Center;
a.City = adm.City;
a.Field = adm.Field;
a.Marks_secured = adm.Marks_secured;
a.out_of = adm.out_of;
a.Class_obtained = adm.Class_obtained;
a.Sports_details = adm.Sports_details;
db.a_model.Add(a);
db.SaveChanges();

return RedirectToAction("Success", "Admission");
}
public ActionResult Success()
{

return View();
}

视图:

@model IEnumerable<ITM_ColLege.Models.AdmissionModel>
@{
ViewBag.Title = "Success";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Admission form successfully submitted</h2>
<h1>Please wait for your admission approval check your status from the menu your admission code 
is  -show id here-

所以我只想为提交录取表格的人显示特定的id。

因此,我已经更新了您想要实现的代码。我在下面为您的现有代码添加了注释。这可能对你有用。

控制器:

public class AdmissionController : Controller
{
contextclass db = new contextclass();        
public ActionResult Admission()
{
return View();
}

[HttpPost]
public ActionResult Admission(AdmissionModel adm)
{
AdmissionModel a = new AdmissionModel();
a.std_name = adm.std_name;
a.std_father = adm.std_father;
a.std_mother = adm.std_mother;
a.DOB = adm.DOB;
a.std_gender = adm.std_gender;
a.R_address = adm.R_address;
a.P_address = adm.P_address;
a.adm_for = adm.adm_for;
a.university = adm.university;
a.E_no = adm.E_no;
a.Center = adm.Center;
a.City = adm.City;
a.Field = adm.Field;
a.Marks_secured = adm.Marks_secured;
a.out_of = adm.out_of;
a.Class_obtained = adm.Class_obtained;
a.Sports_details = adm.Sports_details;
db.a_model.Add(a);
db.SaveChanges();

// Pass in the std_id to the action
return RedirectToAction("Success", "Admission", new {id = a.Std_id});
}

// Pass in the id as a parameter and store it in ViewBag
public ActionResult Success(int id)
{
ViewBag.Id = id;
return View();
}

视图:

@model IEnumerable<ITM_ColLege.Models.AdmissionModel>
@{
ViewBag.Title = "Success";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Admission form successfully submitted</h2>
<h1>Please wait for your admission approval check your status from the menu your admission code 
is  @ViewBag.Id

相关内容

最新更新