Asp.net MVC / jquery MODAL не будет отображаться
Это представление , над которым я работаю, и контроллер, и проблема в том, что когда я нажимаю кнопку отправки, он должен редактировать данные и всплывающее окно с предупреждением отредактировано! и перенаправить на индексное представление , но здесь он редактирует данные и каждый раз предупреждает модальное отсутствие данных :
@model HFC.Models.Patient @{ ViewBag.Title = "Edit"; Layout = "~/Views/Shared/_Layout.cshtml"; } <h3>Edit Patient</h3> <br /> @using (Html.BeginForm()) { <form id="myForm"> <div class="container "> @Html.AntiForgeryToken() <div class="col-md-offset-1 col-md-6 col-xs-12 active" id="sidebar-right" style="border: 0.5px solid rgba(4,4,4,.4) ;margin-left:-30px;bottom:20px; box-shadow: 5px 5px 5px #99ccff; border-radius: 5px; "> <div class="row"> <div class="form-horizontal"> <h3 style="text-align:center; border-radius:5px;margin:1px;padding:10px;color:black">Personal Data</h3> <hr /> @Html.ValidationSummary(true, "", new { @class = "text-danger" }) @Html.HiddenFor(model => model.Id) <div class="form-group"> @Html.LabelFor(model => model.FirstName_, htmlAttributes: new { @class = "control-label col-md-3" }) <div class="col-md-9"> @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.LastName, htmlAttributes: new { @class = "control-label col-md-3" }) <div class="col-md-9"> @Html.EditorFor(model => model.LastName, new { htmlAttributes = new { id = "x", @class = "form-control" } }) @Html.ValidationMessageFor(model => model.LastName, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.DOB, htmlAttributes: new { @class = "control-label col-md-3" }) <div class="col-md-9"> @Html.EditorFor(model => model.DOB, new { htmlAttributes = new { id = "x", @class = "form-control" } }) @Html.ValidationMessageFor(model => model.DOB, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Gender, "Gender", htmlAttributes: new { @class = "control-label col-md-3" }) <div class="col-md-9"> @Html.DropDownList("Gender", null, "Select", new { @class = "form-control" }) @Html.ValidationMessageFor(model => model.Gender, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.PersonalNo_, htmlAttributes: new { @class = "control-label col-md-3" }) <div class="col-md-9"> @Html.EditorFor(model => model.PersonalNo_, new { htmlAttributes = new { id = "x", @class = "form-control" } }) @Html.ValidationMessageFor(model => model.PersonalNo_, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Weight_, htmlAttributes: new { @class = "control-label col-md-3" }) <div class="col-md-9"> @Html.EditorFor(model => model.Weight_, new { htmlAttributes = new { id = "x", @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Weight_, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Height_, htmlAttributes: new { @class = "control-label col-md-3" }) <div class="col-md-9"> @Html.EditorFor(model => model.Height_, new { htmlAttributes = new { id = "x", @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Height_, "", new { @class = "text-danger" }) </div> </div> <br /> <br /> <br /> <br /> </div> </div> </div> <div class="col-md-offset-1 col-md-6 col-xs-12 active" id="sidebar-right" style="border: 0.5px solid rgba(4,4,4,.4) ;margin-left:30px;bottom:20px; box-shadow: 5px 5px 5px #99ccff; border-radius: 5px; "> <div class="row"> <div class="form-horizontal"> <h3 style="text-align:center; border-radius:5px;margin:1px;padding:10px; color:black">Contact Data</h3> <hr /> <div class="form-group"> @Html.LabelFor(model => model.Address1_, htmlAttributes: new { @class = "control-label col-md-3" }) <div class="col-md-9"> @Html.EditorFor(model => model.Address1_, new { htmlAttributes = new { id = "x", @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Address1_, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Address2, htmlAttributes: new { @class = "control-label col-md-3" }) <div class="col-md-9"> @Html.EditorFor(model => model.Address2, new { htmlAttributes = new { id = "x", @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Address2, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.City, htmlAttributes: new { @class = "control-label col-md-3" }) <div class="col-md-9"> @Html.EditorFor(model => model.City, new { htmlAttributes = new { id = "x", @class = "form-control" } }) @Html.ValidationMessageFor(model => model.City, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.ZIPCode_, htmlAttributes: new { @class = "control-label col-md-3" }) <div class="col-md-9"> @Html.EditorFor(model => model.ZIPCode_, new { htmlAttributes = new { id = "x", @class = "form-control" } }) @Html.ValidationMessageFor(model => model.ZIPCode_, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Country_, "Country_", htmlAttributes: new { @class = "control-label col-md-3" }) <div class="col-md-9"> @Html.DropDownList("Country_", null, "Select", new { @class = "form-control" }) @Html.ValidationMessageFor(model => model.Country_, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Tel1_, htmlAttributes: new { @class = "control-label col-md-3" }) <div class="col-md-9"> @Html.EditorFor(model => model.Tel1_, new { htmlAttributes = new { id = "x", @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Tel1_, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Tel2, htmlAttributes: new { @class = "control-label col-md-3" }) <div class="col-md-9"> @Html.EditorFor(model => model.Tel2, new { htmlAttributes = new { id = "x", @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Tel2, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Mobile, htmlAttributes: new { @class = "control-label col-md-3" }) <div class="col-md-9"> @Html.EditorFor(model => model.Mobile, new { htmlAttributes = new { id = "x", @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Mobile, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Email_, htmlAttributes: new { @class = "control-label col-md-3" }) <div class="col-md-9"> @Html.EditorFor(model => model.Email_, new { htmlAttributes = new { id = "x", @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Email_, "", new { @class = "text-danger" }) </div> </div> </div> </div> </div> <div class="col-md-offset-1 col-md-6 col-xs-12 active" id="sidebar-right" style="border: 0.5px solid rgba(4,4,4,.4) ;margin-left:-30px; box-shadow: 5px 5px 5px #99ccff; border-radius: 5px; "> <div class="row"> <div class="form-horizontal"> <h3 style="text-align:center; border-radius:5px;margin:1px;padding:10px;color:black">Health Data</h3> <hr /> <div class="form-group"> @Html.LabelFor(model => model.BlodGroup_, "BlodGroup_", htmlAttributes: new { @class = "control-label col-md-4" }) <div class="col-md-8"> @Html.DropDownList("BlodGroup_", null, "Select", new { @class = "form-control" }) @Html.ValidationMessageFor(model => model.BlodGroup_, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Alergies_, htmlAttributes: new { @class = "control-label col-md-4" }) <div class="col-md-8"> @Html.EditorFor(model => model.Alergies_, new { htmlAttributes = new { id = "x", @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Alergies_, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.ChronicDiseases_, htmlAttributes: new { @class = "control-label col-md-4" }) <div class="col-md-8"> @Html.EditorFor(model => model.ChronicDiseases_, new { htmlAttributes = new { id = "x", @class = "form-control" } }) @Html.ValidationMessageFor(model => model.ChronicDiseases_, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.PatGroup1_, htmlAttributes: new { @class = "control-label col-md-4" }) <div class="col-md-8"> @Html.EditorFor(model => model.PatGroup1_, new { htmlAttributes = new { id = "x", @class = "form-control" } }) @Html.ValidationMessageFor(model => model.PatGroup1_, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.PatGroup2_, htmlAttributes: new { @class = "control-label col-md-4" }) <div class="col-md-8"> @Html.EditorFor(model => model.PatGroup2_, new { htmlAttributes = new { id = "x", @class = "form-control" } }) @Html.ValidationMessageFor(model => model.PatGroup2_, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.InsuranceCompany_, htmlAttributes: new { @class = "control-label col-md-4" }) <div class="col-md-8"> @Html.EditorFor(model => model.InsuranceCompany_, new { htmlAttributes = new { id = "x", @class = "form-control" } }) @Html.ValidationMessageFor(model => model.InsuranceCompany_, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.InsuranceCode_, htmlAttributes: new { @class = "control-label col-md-4" }) <div class="col-md-8"> @Html.EditorFor(model => model.InsuranceCode_, new { htmlAttributes = new { id = "x", @class = "form-control" } }) @Html.ValidationMessageFor(model => model.InsuranceCode_, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.InsuranceExpireDate_, htmlAttributes: new { @class = "control-label col-md-4" }) <div class="col-md-8"> @Html.EditorFor(model => model.InsuranceExpireDate_, new { htmlAttributes = new { id = "x", @class = "form-control" } }) @Html.ValidationMessageFor(model => model.InsuranceExpireDate_, "", new { @class = "text-danger" }) </div> </div> </div> </div> </div> <div class="col-md-offset-1 col-md-6 col-xs-12 active" id="sidebar-right" style="border: 0.5px solid rgba(4,4,4,.4) ;margin-left:30px; box-shadow: 5px 5px 5px #99ccff; border-radius: 5px; "> <div class="row"> <div class="form-horizontal"> <h3 style="text-align:center; border-radius:5px;margin:1px;padding:10px; color:black">Read Only Data</h3> <hr /> <div class="form-group"> @Html.LabelFor(model => model.ProfessionalID_, htmlAttributes: new { @class = "control-label col-md-4" }) <div class="col-md-8"> @Html.EditorFor(model => model.ProfessionalID_, new { htmlAttributes = new { id = "x", @class = "form-control" } }) @Html.ValidationMessageFor(model => model.ProfessionalID_, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.InstitutionID_, htmlAttributes: new { @class = "control-label col-md-4" }) <div class="col-md-8"> @Html.EditorFor(model => model.InstitutionID_, new { htmlAttributes = new { id = "x", @class = "form-control" } }) @Html.ValidationMessageFor(model => model.InstitutionID_, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.UserId_, htmlAttributes: new { @class = "control-label col-md-4" }) <div class="col-md-8"> @Html.EditorFor(model => model.UserId_, new { htmlAttributes = new { id = "x", @class = "form-control" } }) @Html.ValidationMessageFor(model => model.UserId_, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.HCEID_, htmlAttributes: new { @class = "control-label col-md-4" }) <div class="col-md-8"> @Html.EditorFor(model => model.HCEID_, new { htmlAttributes = new { id = "x", @class = "form-control" } }) @Html.ValidationMessageFor(model => model.HCEID_, "", new { @class = "text-danger" }) </div> </div> </div> </div> </div> </div> <div class="btn-toolbar" style="float:left;"> <br /> <input type="submit" value="Save" class="btn btn-primary" id="btnSubmit" /> </div> </form> } <br /> <script src="~/Scripts/jquery-1.10.2.min.js"></script> <script> $(document).ready(function () { $("#btnSubmitT").click(function () { var data = $("#myForm").serialize(); var newUrl = '@Url.Action("Index","Patients")'; $.ajax({ type: "POST", url: "/Patients/Edit", data: data, success: function (response) { $('#your-modal').fadeTo(2000, 600).slideUp(600, function () { $('#your-modal').slideUp(600); window.location.href = newUrl; }); }, error: function (response) { // alert('No Data '); $('#your-modal2').fadeTo(2000, 600).slideUp(600, function () { $('#your-modal2').slideUp(600); }); } }) }) }) </script> <script src="~/Scripts/jquery.validate.min.js"></script> <script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script> <div class="alert alert-success" id="your-modal" hidden="hidden"> EDITED </div> <div class="alert alert-warning" id="your-modal2" hidden="hidden"> No Data </div> <style> #your-modal { text-align: center; } #your-modal2 { text-align: center; } #x:hover { padding: 15px; border: 1px solid #6699ff; border-bottom-width: 2px; background-color: transparent; } .col-md-6.active:hover { box-shadow: 2px 2px 2px 2px rgba(4,4,4,.4) !important; } .col-md-12.active:hover { box-shadow: 2px 2px 2px 2px rgba(4,4,4,.4) !important; } </style>
public ActionResult Edit([Bind(Include = "Id,FirstName_,LastName,DOB,Gender,PersonalNo_,Address1_,Address2,City,ZIPCode_,Country_,Tel1_,Tel2,Mobile,Email_,BlodGroup_,Alergies_,ChronicDiseases_,InsuranceCompany_,InsuranceCode_,InsuranceExpireDate_,UserId_,ProfessionalID_,InstitutionID_,HCEID_,Weight_,Height_,PatGroup1_,PatGroup2_")] терпеливый терпеливый)
{
if (ModelState.Функция IsValid)
{
БД.запись(пациент).State = EntityState.Модифицированный;
дБ.Метод SaveChanges();
return RedirectToAction("индекс");
}
Видовой мешок.BlodGroup_ = новый списка(БД.Пациенты, "BlodGroup_", "BlodGroup_" , пациенту.BlodGroup_);
Видовой мешок.Пол = новый списка(БД.Пациенты, "пол", "гендер", пациенту.Пол);
Видовой мешок.Country_ = новый списка(БД.Пациенты, "Country_", "Country_", пациенту.Страна_);
обратный вид(пациент);
}
Что я уже пробовал:
-----------------------------------------------------------------
Karthik_Mahalingam
добавьте этот код и посмотрите, какое сообщение об ошибке вы получаете
error: function(xhr, status, error) { alert(xhr.responseText); }
ddgjgj
нет , я хочу, чтобы в случае ошибки, чтобы показать alert2
j snooze
Ну, если бы мне пришлось угадывать, я бы сказал, что у вас нигде нет определения your-modal или your-modal2. Вам нужен div с идентификатором "свой-модальные" и "свой-modal2" что вы хотите, чтобы диалоговое окно, чтобы посмотреть, как. Вам также нужно определить его в готовой функции javascript (которая у вас есть) $("#your-modal").dialog();...Я не вижу ничего подобного в вашем javascript. Я думаю, что лучшее, что вы можете сделать, это посетить https://jqueryui.com/dialog/...может быть, это не то, чего вы пытаетесь достичь? Наверное, я тоже нигде не вижу ссылки на скрипт виджетов пользовательского интерфейса jquery.