This is the view that im working on and the controller , and the problem is when i press submit button it should edit data and popup an alert EDITED! and redirect to Index view , but here it edits the data and every time alert the modal NO DATA :
@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) {
$('#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_")] Patient patient)
{
if (ModelState.IsValid)
{
db.Entry(patient).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.BlodGroup_ = new SelectList(db.Patients, "BlodGroup_", "BlodGroup_" , patient.BlodGroup_);
ViewBag.Gender = new SelectList(db.Patients, "Gender", "Gender", patient.Gender);
ViewBag.Country_ = new SelectList(db.Patients, "Country_", "Country_", patient.Country_);
return View(patient);
}
What I have tried:
-----------------------------------------------------------------