Click here to Skip to main content
16,005,038 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Controller code

public ActionResult GatePass( )//for Populate the values on GatePass View
{
Guid aId = new Guid();
AppointmentModel objAppointmentModel = new AppointmentModel();
objAppointmentModel = this._iAppointmentService.GetAppointmentByAckId(aId);
return View(objAppointmentModel);


}


[HttpPost]//For Populate the values on GatePass View based on Given acknowledgementId
public ActionResult GatePass(AppointmentModel appointmentModel)
{



List<validationresult> ValidationResultlist = this._iAppointmentService.GatePassValidation(appointmentModel);
if (ValidationResultlist != null && ValidationResultlist.Count() > 0)
{
// VisitorModel objvisitorModel = this._iAppointmentService.InitiateVisitor();
// appointmentModel.SecurityQuestionList = objvisitorModel.SecurityQuestionList;

ControllerExtensions.AddModelErrors(this, ValidationResultlist);
//return View("GatePass", appointmentModel);
return View(appointmentModel);
}
else
{
AppointmentModel objAppointmentModel = new AppointmentModel();
if (appointmentModel.AcknowledgementID != Guid.Empty)
{
objAppointmentModel = this._iAppointmentService.GetAppointmentByAckId(appointmentModel.AcknowledgementID);

}
return View(objAppointmentModel);
}

}
Validation method


public List<validationresult> GatePassValidation(Models.AppointmentModel appointmentModel)
{
List<validationresult> gatePassvalidationResultlist = new List<validationresult>();
try
{
if (appointmentModel == null)
{
ValidationResult vr = new ValidationResult();
vr.MemberName = "GlobleError";
vr.Message = "Appointment Record not found";
gatePassvalidationResultlist.Add(vr);
}

if (string.IsNullOrEmpty(appointmentModel.AcknowledgementID.ToString() ))
{
ValidationResult vr = new ValidationResult();
vr.MemberName = "AcknowledgementID";
vr.Message = "Please enter ID";
gatePassvalidationResultlist.Add(vr);
}
}
catch (Exception ex)
{
ValidationResult vr = new ValidationResult();
vr.MemberName = "GlobleError";
vr.Message = "Error : " + ex.Message;
gatePassvalidationResultlist.Add(vr);

}
return gatePassvalidationResultlist;
}


.cshtml

@Html.LabelFor(model => model.VisitorName, new { htmlAttributes = new { @class = "form-control input-sm " } })I am getting error in this line argument null exception was unhandled by user code”
Posted

1 solution

Not a very clear question but maybe these tips can help you:



  1. Use a breakpoint to check the values using the debugger. You can also use breakpoints is views.
  2. Other code uses appointmentModel instead of model. Maybe a typo?

Good luck!

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900