public IActionResult Exam(HttpClient httpContent) { var a = int.Parse(Request.Form["all"]); var resultarr = new string[3]; var str = ""; var arr = new string[a + 1]; var result = 0; int count_all = 0; ExamModel answer = new ExamModel(); List <Examanswer_List> examanswers = new List <Examanswer_List>(); Examanswer_List examanswer = new Examanswer_List(); //for(int i = 0;i <= a;i++ ) //{ // answer = _ExamService.GetExamModelById(int.Parse(resultarr[1])); // count_all += (int)answer.Score; // str = Request.Form["Ans" + i]; // resultarr = str.Split("%%%,"); // if(answer.Answer == resultarr[0]) // { // result += (int)answer.Score; // } // result_str += (resultarr + ";"); //} for (int i = 0; i <= a; i++) { str = Request.Form["Ans" + i]; resultarr = str.Split("%%%,"); answer = _ExamService.GetExamModelById(int.Parse(resultarr[1])); count_all += (int)answer.Score; examanswer.ExamId = answer.Id; examanswer.Answer = resultarr[0]; if (answer.Answer == resultarr[0]) { result += (int)answer.Score; examanswer.Result = true; } else { examanswer.Result = false; } examanswers.Add(new Examanswer_List { Answer = examanswer.Answer, ExamId = examanswer.ExamId, Result = examanswer.Result, }); } string result_str = ExamSplit.ListToString(examanswers); Examination_form form = new Examination_form(); form.Count = (int)(100 * result / count_all); form.DateTime = DateTime.Now; form.Result = result_str; string user; string Uid; Request.Cookies.TryGetValue("User", out user); Request.Cookies.TryGetValue("Uid", out Uid); var u = _UserService.InspectGuid(new TGuid { User = user, Uid = Uid, }); form.UserModel = u; _ExamService.AddExamResult_form(form); //for(int i = 0; i < a; i++) //{ // UserExamModels[] //} //return View("ExamResult"); //return RedirectToAction(nameof(ExamResult)); return(Json(new { count = form.Count, })); }