Guest User

Untitled

a guest
Aug 6th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.30 KB | None | 0 0
  1. loading or refreshing only the partial view using Ajax
  2. `@Html.Partial("_MusicPlayer")`
  3.  
  4.  
  5. `@using (Ajax.BeginForm("Index", new AjaxOptions { `
  6. `hereHttpMethod="GET",`
  7. ` InsertionMode = InsertionMode.Replace,
  8. UpdateTargetId = "albumlist"
  9. }))
  10. {
  11. <div id="newrealeaseformcontent">
  12. <h2>New Releases(@Model.Genre)</h2>
  13. <div id="daterangesearchcntrl">
  14. @Html.HiddenFor(m => m.Genre)
  15. @Html.Label("choose release date")
  16. @Html.TextBoxFor(m => m.DateRange, new { @readonly = "readonly", @id = "daterange" })
  17. <input class="sb_search" type="submit" value=""/>
  18. </div>
  19. <br />
  20. <br />
  21. <br />
  22. <div id="albumlist">
  23. <ul id="newreleasealbum-list">
  24. @foreach (var album in Model.Albums)
  25. {
  26. <li style="margin-left:0px;padding-left:0px">
  27. <a href="@Url.Action("AlbumPopup", new { id = album.AlbumId })" class="openPlayer">
  28. <img alt="@album.Title" width="75" height="74" src="@album.AlbumPhoto.ThumbnailPath" />
  29. <div class="clear"></div>
  30. </a>
  31. </li>
  32. }
  33. </ul>
  34. <div class="clear"></div>
  35. </div>
  36. </div>
  37. }
  38. </div> `
  39.  
  40. public class MusicModel
  41. {
  42. private IList<Album> _albums;
  43. public MusicModel()
  44. {
  45. _albums = new List<Album>();
  46. }
  47. public int Id { get; set; }
  48. public string Genre { get; set; }
  49. public string DateRange { get; set; }
  50. public IList<Album> Albums { get { return _albums; } set { _albums = value; } }
  51.  
  52.  
  53. }
  54. public class Album
  55. {
  56. public int AlbumId { get; set; }
  57. public string Title { get; set; }
  58. public string AlbumPath { get; set; }
  59. }
  60.  
  61. public ActionResult musicTest()
  62. {
  63. var model = new MusicModel();
  64. return View(model);
  65. }
  66.  
  67. public JsonResult RefreshMusicList(int id)
  68. {
  69. var musicList = GetMovieListById(id);
  70. return Json(musicList);
  71. }
  72.  
  73. @*Here is your model*@
  74. @model ST.Web.Models.MusicModel
  75. @Html.Partial("_MusicPlayer")
  76. <div id="newrealeaseformcontent">
  77. <h2>
  78. New Releases(@Model.Genre)</h2>
  79. <div id="daterangesearchcntrl">
  80. @Html.HiddenFor(m => m.Genre)
  81. @Html.Label("choose release date")
  82. @Html.TextBoxFor(m => m.DateRange, new { @readonly = "readonly", @id = "daterange" })
  83. <input class="sb_search" type="submit" value="" />
  84. </div>
  85. <br />
  86. <br />
  87. <br />
  88. <div id="albumlist">
  89. <a href="JavaScript:UpdateAlbumList('@(Model.Id)')">Update List</a>
  90. <ul id="newreleasealbum-list">
  91.  
  92. @foreach (var album in Model.Albums)
  93. {
  94. <li style="margin-left: 0px; padding-left: 0px">
  95. <a href="@Url.Action("AlbumPopup", new { id = album.AlbumId })" class="openPlayer">
  96. <img alt="@album.Title" width="75" height="74" src="@album.AlbumPath @*@album.AlbumPhoto.ThumbnailPath*@" />
  97. </a>
  98. </li>
  99. }
  100. </ul>
  101. <div class="clear">
  102. </div>
  103. </div>
  104. </div>
  105.  
  106. <script type="text/javascript">
  107. function UpdateAlbumList(id)
  108. {
  109. var action = "@(Url.Action("RefreshMusicList", "Sample"))";
  110. var postData = "id="+id;
  111. $.ajax({
  112. cache: false,
  113. type: "POST",
  114. dataType: 'JSON',
  115. url: action,
  116. data: postData,
  117. beforeSend: function () {
  118. //showAjaxLoading(); //show the ajax loading panel
  119. },
  120. success: function (data) {
  121. //console.log(data);
  122. //here you can bind your movie list
  123. },
  124. complete: function () {
  125. //hideAjaxLoading(); //hide ajax loading panel
  126. },
  127. error: function (xhr, ajaxOptions, thrownError) {
  128. //showError("Failed to update !!");
  129. alert(thrownError);
  130. }
  131. });
  132. }
  133. </script>
Add Comment
Please, Sign In to add comment