0

The code below run perfectly when ran on my local machine I managed to update the patient details but when i published the application to IIS server I am having the error attached. Any suggestion where I am going wrong

enter image description here

C#

     // Edit Patient Details
    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Edit(PatientDetail patientDetail,DateTime DOB)
    {
        if (ModelState.IsValid)
        {
            var currentUser = db.vwUsers.FirstOrDefault(i => i.DomainUserName == User.Identity.Name);
            var apptime = DateTime.Now;

            //// Save today's date.             
            var age = apptime.Year - DOB.Year;
            //PatientDetail patientDetail = new PatientDetail();
            patientDetail.Age =Convert.ToString(age);
            patientDetail.LastUpdatedByUser = currentUser.FullName;
            patientDetail.LastUpdatedByUserID = currentUser.AdUserName;
            patientDetail.LastUpdatedOn = apptime;
            db.Entry(patientDetail).State = EntityState.Modified;
            db.SaveChanges();
            return RedirectToAction("Edit", new { id = patientDetail.Id, updatemessage = 1 });
        }
        return View();
    }

Chtml

      @model MPFT.SendIT.Models.NewChangeIT.PatientDetail @using 
     (Html.BeginForm()) { @Html.AntiForgeryToken()

     <div class="panel-body">
     <div class="form-horizontal">

       @Html.ValidationSummary(true, "", new { @class = "text-danger" }) @Html.HiddenFor(model => model.Id)

    <div class="form-group">
        @Html.LabelFor(model => model.Surname, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.Surname, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Surname, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.Firstname, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.Firstname, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Firstname, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.NHSNumber, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.NHSNumber, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.NHSNumber, "", new { @class = "text-danger" })
        </div>
    </div>
</div>
}
  • 1
    If, for any reason, you don't receive a valid _patientDetail_ or if you cannot find a _currentUser_ your code is doomed by this exception. Also we cannot see if this code could be called only after authentication. If yes then your User.Identity is probably invalid. – Steve Dec 19 '18 at 13:32
  • @Steve thanks I follow your suggestion. The way I wrote the code in the controller is wrong I need to change it. Thanks for your help – Eric Aime Tchatchoua Dec 19 '18 at 13:48

0 Answers0