I have a controller in my mvc which is responsible for updating database when a button is clicked. I am using entity framework for updation of data to database, my question is how to put an alert that "database updated successfully"?
below approach I am trying but the alert does not show up.
public ActionResult LookupManagementUpdate(int[] AutoID){
DAL.SupportCenterMethods obj = new DAL.SupportCenterMethods();
var Mode = Request.Form["ddlTables"].ToString();
DigitalReadinessEntities entities = new DigitalReadinessEntities();
ViewBag.TaskCompleted = 0;
int Cnt_element = 0;
int orderby = 1;
foreach (int id in AutoID)
{
if (id == 0)
{
Cnt_element++;
continue;
}
else
{
var value = entities.TBL_MASTER_INTAKE_ASSIGNED_TO.Find(id);
value.Preference = orderby;
entities.SaveChanges();
orderby += 1;
Cnt_element++;
}
}
if(Cnt_element==AutoID.Length)
{
ViewBag.TaskCompleted = 1;
ViewBag.cmp = "Row Ordering completed";
}
if (Mode != "")
{
ViewBag.data = obj.GetLookUpTableData(Convert.ToInt32(Mode));
ViewData["Tables"] = new SelectList(obj.GetLookUpTables(0).ToList(), "Mode",
"tablename", Mode);
}
return View("LookUpManagement");
}
This is the logic used in above controller
if(Cnt_element==AutoID.Length)
{
ViewBag.TaskCompleted = 1;
ViewBag.cmp = "Row Ordering completed";
}
I had set a counnter and if the database updation is completed ViewBag.cmp will have the alert message in it.
In view:
<script type="text/javascript">
$(function () {
alert(ViewBag.cmp);});
</script>
but nothing shows up when the updation is completed.
Please help to rectify the code or provide any alternative you are aware of...