I just started using Html.RenderPartial (usercontrol, model) to display my user controls. Can this functionality be changed to show an Ajax boot image when loading a partial view?
EDIT: I tried, but could not get it to work. I have a partial view (_FixtureList.cshmtl):
@model List<Areas.Gameplan.Models.Fixture> @foreach (var item in this.Model) { <tr> <td class="teamgrid">@Html.Encode(item.Week)</td> <td><img src='@Html.Encode(item.Logo)' alt="Logo" /></td> <td class="teamgrid">@Html.Encode(item.Opponent)</td> <td class="teamgrid">@Html.Encode(item.Result)</td> </tr>
And currently I'm browsing the page:
public ActionResult Cincinnati() { //renderpartial List<Fixture> lstFixtures = _Base.DataRepository.GetFixtureList("2017", "Cincinnati"); return View(lstFixtures); }
}
And this is an important part of my view (Cincinnati.cshtml):
@model List<Areas.Gameplan.Models.Fixture> @{ ViewBag.Title = "Cincinnati Bengals"; Layout = "~/Areas/Gameplan/Views/Shared/_Layout.cshtml"; } <div id="bigborder"> <p> <br /> <div class="sidebarleftteam"> <div id="divFixtures"> <table id='tblFixtures' align='center'><tr><th><img src='../../../../Content/Images/Gameplan/fixtureweek.jpg' /></th><th><img src='../../../../Content/Images/Gameplan/fixtureopponent.jpg' /></th><th/><th><img src='../../../../Content/Images/Gameplan/fixturescore.jpg' /></th></tr> @{ Html.RenderPartial("_FixtureList", this.Model); } </table>
How to apply your example to this code?
EDIT:
Thought this is how I did it:
public ActionResult MyPartial() { List<Fixture> lstFixtures = _Base.DataRepository.GetFixtureList("2016", "Cincinnati"); return PartialView("_FixtureList", lstFixtures); }
And in the view:
$.ajax( { type: 'POST', async: true, contentType: 'application/json; charset=utf-8', dataType: 'html', url: 'MyPartial', beforeSend: function (xhr) { $('#mydiv').addClass('ajaxRefreshing'); xhr.setRequestHeader('X-Client', 'jQuery'); }, success: function (result) { $('#mydiv').html("<table id='tblFixtures' align='center'><tr><th><img src='../../../../Content/Images/Gameplan/fixtureweek.jpg' /></th><th><img src='../../../../Content/Images/Gameplan/fixtureopponent.jpg' /></th><th/><th><img src='../../../../Content/Images/Gameplan/fixturescore.jpg' /></th></tr>" + result + "</table>"); }, error: function (error) { alert(error); }, complete: function () { $('#mydiv').removeClass('ajaxRefreshing'); } });