I have made a admission form so after on submitting the form it redirects to another page called "Success" there I want to display the student id or the primary id for each admission form is submitted which is generated in the model my codes are below:
Model :
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; }
}
Controller:
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();
}
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-
so I want to display specific id only for one who submits the admission form only.
So, I have updated the code of what you want to achieve. I added comments below to your existing code. This might work for you.
CONTROLLER:
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();
}
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.