Ali_100 Ответов: 0

Вновь созданная запись не отображается до тех пор, пока не появится ссылка


it is my create post of partial view

[HttpPost]
       public ActionResult CreateEmployeeEmail(EmployeeEmailModel model)
       {
           #region

           AjaxResponse ajaxResponse;
           if (model.EmailTypeId.ToString() == EmailTypes.Office.GetEnumDescription() && ModelState.ContainsKey("Email"))
           {
               ModelState["Email"].Errors.Clear();
           }
           else if (model.EmailTypeId.ToString() == EmailTypes.Personal.GetEnumDescription() && ModelState.ContainsKey("OfficialEmail"))
           {
               ModelState["OfficialEmail"].Errors.Clear();
           }
           #endregion
           if (ModelState.IsValid)
           {
               var employeeModel = new EmployeeModel();
               var employee = _employeeService.GetByIdWithDetail(model.EmpId);
               if (model.EmailTypeId.ToString() == EmailTypes.Office.GetEnumDescription())
               {
                   employee.ModifiedBy = CurrentUserId;
                   employee.EmailAccountId = model.OfficialEmail;
                   _employeeService.Update(employee);
                   _employeeService.SaveChanges();
               }
               if (model.EmailTypeId.ToString() == EmailTypes.Personal.GetEnumDescription())
               {
                   var contactEmailInfoModel = new ContactEmailInfoModel();
                   var contactEmail = new ContactEmailInfo();
                   contactEmailInfoModel.ContactId = employee.ContactId;
                   contactEmailInfoModel.IsPrimary = true;
                   contactEmailInfoModel.Email = model.Email;
                   contactEmailInfoModel.Type = model.EmailTypeId.GetEnumDescription();
                   contactEmail.ObjectState = Repository.Pattern.Base.Infrastructure.ObjectState.Added;
                   contactEmailInfoModel.FillEntity(contactEmail);
                   _contactEmailInfoService.Insert(contactEmail);
                   _contactEmailInfoService.SaveChanges();
               }

               var employeewithEmailAccount = _employeeService.GetEmployeewithEmailAccountbyEmpId(model.EmpId);

               var emailEmployeelst = new List<employeeemailmodel>();
               emailEmployeelst = EmployeeEmailModel.FillModelList(_contactEmailInfoService.GetAll().ToList());
               ViewBag.EmpId = model.EmpId;

               if (employeewithEmailAccount != null && employeewithEmailAccount.EmailAccount != null)
               {
                   emailEmployeelst.Add(new EmployeeEmailModel
                   {
                       Id = employeewithEmailAccount.Id,
                       Email = employeewithEmailAccount.EmailAccount.Email,
                       Type = EmailTypes.Office.GetEnumDescription(),
                       TypeId = (int)EmailTypes.Office
                   });
               }
               var message = _contactService.PrepareErrorMessage("responds.createsuccessful");
               ajaxResponse = new AjaxResponse
               {
                   Status = AjaxStatus.Success.ToInt(),
                   Message = new List<string> { message },
                   Data = PartialViewToString("_EmployeeEmail", emailEmployeelst)
               };
               return Json(ajaxResponse, JsonRequestBehavior.AllowGet);
           }
           FillEmailsDropDowns();
           ajaxResponse = new AjaxResponse
           {
               Data = PartialViewToString("CreateEmployeeEmail", model)
           };
           return Json(ajaxResponse, JsonRequestBehavior.AllowGet);
       }


it is my main partial view get


[HttpGet]
        public ActionResult EmployeeEmail(int empId)
        {
            var model = new EmployeeEmailModel();
            ViewBag.EmpId = empId;

            if ((int)model.EmailTypeId == 0)
                model.EmailTypeId = EmailTypes.Personal;

            var emailEmployeelst = new List<EmployeeEmailModel>();
            emailEmployeelst = EmployeeEmailModel.FillModelList(_contactEmailInfoService.GetAll().ToList());

            var employee = _employeeService.GetEmployeewithEmailAccountbyEmpId(empId);
            if (employee != null && employee.EmailAccount != null)
            {
                emailEmployeelst.Add(new EmployeeEmailModel
                {
                    Id = employee.Id,
                    Email = employee.EmailAccount.Email,
                    Type = EmailTypes.Office.GetEnumDescription(),
                    TypeId = (int)EmailTypes.Office
                });
            }
            return PartialView("_EmployeeEmail", emailEmployeelst);
        }

& it is the Get of this partial view


[HttpGet]
     public ActionResult CreateEmployeeEmail(int empId)
     {
         var model = new EmployeeEmailModel();
         ViewBag.EmpId = model.EmpId = empId;

         AjaxResponse ajaxResponse;
         if ((int)model.EmailTypeId == 0)
             model.EmailTypeId = EmailTypes.Personal;
         FillEmailsDropDowns();
         ajaxResponse = new AjaxResponse
         {
             Data = PartialViewToString("CreateEmployeeEmail", model)
         };
         return Json(ajaxResponse, JsonRequestBehavior.AllowGet);
     }


when i successfully Created new record, the list are update in the create post last stage

but it is  not showing in the main grid after the new record untill i refresh the page. What should to i do? to display the new record? is there any redirect issue ?

The image of Solution Files is

https://postimg.org/image/jsmmtrdw9/


Что я уже пробовал:

После многих исправлений, но безуспешных до сих пор. Добавлен
Я изменил имя частичного представления, например, с '_EmployeeEmail.cshtml' на
"EmployeeEmail.cshtml", но это не сработает.

0 Ответов