After my database update I am showing viewbag.result ='Successfully updated' and when I debug the value is stored in viewbag.result but it is not showing when I call
Return view(). Why does the document ready function is not firing after calling the view() , Please help it would be very appreciated
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
410 Points
1326 Posts
Message is not showing in $(document).ready(function() after return to view, Please help
Oct 14, 2019 08:14 AM|polachan|LINK
After my database update I am showing viewbag.result ='Successfully updated' and when I debug the value is stored in viewbag.result but it is not showing when I call
Return view(). Why does the document ready function is not firing after calling the view() , Please help it would be very appreciated
My code has been given below
Many Thanks
Pol
Contributor
2690 Points
874 Posts
Re: Message is not showing in $(document).ready(function() after return to view, Please help
Oct 14, 2019 09:45 AM|Rena Ni|LINK
Hi polachan,
For how to alert ViewBag,you need to use the following code:
In your scenario,you use ajax,so you would always get into the error function due to you have return View,you need to modify your code like below:
1.View(Actually,if you use alert in document.ready(),it would alert every time you refresh the page.I suggest that you could alert after call ajax):
2.Controller:
[HttpPost] public IActionResult ResetAttendance(string option, string depots, string departments, string EmpIds, string fromdate, string todate) { UtilityBLL.ResetAttendanceOfEmployees(EmpIds, attDatefrom, attDateto, option, connectionSettings); ViewBag.Result = "Saved Succesfully"; ModelState.Clear(); return Json(new { newUrl = Url.Action("Test", "Home") , result= ViewBag.Result });//return to the view you wanted. //return View(); }
3.Result:
Best Regards,
Rena