Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8266369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:08:08+00:00 2026-06-08T05:08:08+00:00

I have just started using Html.RenderPartial(usercontrol, model) to render my user controls. Is it

  • 0

I have just started using Html.RenderPartial(usercontrol, model) to render my user controls. Is it possible to change this functionality to show an Ajax loading image while the partial view loads?

EDIT : Had a try at this, but have been unable to get it to work. I have a partial view like this (_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 this is currently how I am rendering the page :

public ActionResult Cincinnati()
    {
        //renderpartial
        List<Fixture> lstFixtures = _Base.DataRepository.GetFixtureList("2017", "Cincinnati");

        return View(lstFixtures);
    }

}

And this is the relevant 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 would I apply your example to this code?

EDIT :

Figured it out, 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');
     }
 });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T05:08:10+00:00Added an answer on June 8, 2026 at 5:08 am

    Is it possible to change this functionality to show an Ajax loading image while the partial view loads?

    No, Html.RenderPartial doesn’t use any AJAX, the content is directly included on the server.

    If you want to use AJAX instead of Html.RenderPartial put a div in your view:

    <div id="mydiv" data-url="@Url.Action("MyPartial", "Home")"></div>
    

    then write a controller action that will return your partial:

    public class HomeController: Controller
    {
        // that's the action that serves the main view
        public ActionResult Index()
        {
            return View();
        }
    
        // that's the action that will be invoked using AJAX and which 
        // will return the partial view
        public ActionResult MyPartial()
        {
            var model = ...
            return PartialView(model);
        }
    }
    

    then you will have the corresponding partial (~/Views/Home/Myartial.cshtml):

    @model MyViewModel
    ...
    

    and the last step is to write javascript that will trigger the AJAX call:

    $(function() {
        var myDiv = $('#mydiv');
        $.ajax({
           url: myDiv.data('url'),    
           type: 'GET',
           cache: false, 
           context: myDiv,
           success: function(result) {
               this.html(result);
           }
        });
    });
    

    and the last piece is to show a loading animation. This could be done in multiple ways. One way is to use the global ajax event handlers:

    $(document).ajaxSend(function() {
        // TODO: show your animation
    }).ajaxComplete(function() {
        // TODO: hide your animation
    });
    

    Another possibility is to simply put some text or image in your div initially:

    <div id="mydiv" data-url="@Url.Action("MyPartial", "Home")">
        Loading ...
    </div>
    

    and since the contents of this div will be replace in the success callback of the ajax call with the contents of the partial, the loading text will disappear. Just be careful with this because if there is an error the success callback won’t trigger and the div will stay with its initial text. So the complete handler is preferred in this case to hide the animation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just started using MVC3. I am using fields like this: <div class=editor-field> @Html.TextBoxFor(model
Let me preface this question. I have just started using jquery, so please be
I'm just getting started using Mustache and I have this rendering problem. I send
I have just started considering using the HTML 5 api for a Rails/JQuery project,
I have just started using the <% Html.DevExpress().DateEdit() control and i got it to
i have just started using Moq ver (3.1) and i have read blogs and
I have just started using jQuery and although following code gets the job done,
I have just started using the Data Access Application Block from microsoft. There are
I have just started using C2DM. I prefer to send REGISTRATION intent only once
I have just started using Vim in a terminal (PuTTY or MinTTY), after always

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.