Remark :
Ajax.ActionLink Applications
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
//GET: AllTeachers /// <summary> /// List all Teachers from datasource /// </summary> /// <returns></returns> public ActionResult AllTeachers() { TchDBContext db = new TchDBContext(); //Thread.Sleep(1000); return PartialView(db.Teachers.OrderBy(x => x.Name).ToList()); } //GET: AllSchools /// <summary> /// List all schools from DataSource /// </summary> /// <returns></returns> public ActionResult AllSchools() { SchDBContext db = new SchDBContext(); try { //Thread.Sleep(1000); return PartialView(db.Schools.OrderBy(x => x.Name).ToList()); } catch { return View(); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
@section head { <title> Ajax.ActionLink </title> } @*CSS for Loading GIF Image*@ <style> .HideLoader { display: none; } .ShowLoader { display: normal; } </style> @*JS to Show and Hide Loading GIF Image*@ <script> function onAjaxBegin() { $("#divLoading").removeClass("ShowLoader").addClass("ShowLoader"); } function onAjaxComplete() { $("#divLoading").removeClass("ShowLoader").addClass("HideLoader"); } </script> @Ajax.ActionLink( "List All Schools", // <-- Text to display "AllSchools",// <-- Action/Method Name "Home",//<!-- Controller Name new AjaxOptions { UpdateTargetId = "UpdateContentDiv", // <-- DOM element ID to update InsertionMode = InsertionMode.Replace, // <-- Replace the content of DOM element HttpMethod = "GET", // <-- HTTP method LoadingElementId = "divLoading", //Id of Loading GIF Image OnBegin = "onAjaxBegin", //OnBegin JS Function OnComplete = "onAjaxComplete" //OnComplete JS Function }, new { @class = "btn btn-primary" } //-- Class ) @Ajax.ActionLink( "List All Teachers", // <-- Text to display "AllTeachers",// <-- Action/Method Name "Home",//<!-- Controller Name new AjaxOptions { UpdateTargetId = "UpdateContentDiv", // <-- DOM element ID to update InsertionMode = InsertionMode.Replace, // <-- Replace the content of DOM element HttpMethod = "GET", // <-- HTTP method LoadingElementId = "divLoading", //Id of Loading GIF Image OnBegin = "onAjaxBegin", //OnBegin JS Function OnComplete = "onAjaxComplete" //OnComplete JS Function }, new { @class = "btn btn-primary" } //-- Class ) <div id="divLoading" class="divhide"> @*divhide will be set as default and will be changed dynamically.*@ <img src="~/images/loading.gif" /> </div> <div id="UpdateContentDiv"> @*Div to update content after Ajax Call*@ </div> |