Hello guys I am making a college website project in MVC it has admission form so whenever a admission form is filled by user and gets submitted it goes for approval and the user receives his admission code to check the status of his/her account approval so I am having a problem here.
The Code:
Model:
public partial class admission_tbl
{
public int adm_id { get; set; } //- by this user checks his status//
[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; }
[AgeRangeValidation(ErrorMessage = "Age must be between 18 - 28", MinAge = 18, MaxAge = 28)]
[Required]
[DataType(DataType.Date), DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public System.DateTime DOB { get; set; }
[Required]
public string std_gender { get; set; }
[Required]
public string R_address { get; set; }
[Required]
public string P_address { get; set; }
[Required]
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; }
[Required]
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; }
public string Sports_details { get; set; }
public string adm_status { get; set; } //--This is the method which i am using to control account
approval or non approval status.
}}
Controller:
public ActionResult Status_check()
{
return View();
}
[HttpPost]
public ActionResult Status_check(admission_tbl svm)
{
admission_tbl u = db.admission_tbl.Where(a => a.adm_id == svm.adm_id).SingleOrDefault();
if (u.adm_status == "Approved")
{
ViewBag.Message1 = "Your account is Approved";
}
else if (u.adm_status == "Unapproved")
{
ViewBag.Message = "Your account is not Approved ";
}
else
{
ViewBag.Message = "Your account is in pending please wait";
}
return View();
}
So, here in status check the user inputs his admission code to check whether account is approved or not everything works fine but the problem is when I try to input a random number input it throws null exception error instead I want to throw a message error for example "Invalid Admission Code no such exists" i couldn't catch it what am i missing?